From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2B6FEDE98C for ; Thu, 14 Sep 2023 08:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235999AbjINICh (ORCPT ); Thu, 14 Sep 2023 04:02:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231274AbjINICg (ORCPT ); Thu, 14 Sep 2023 04:02:36 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C41061BFB for ; Thu, 14 Sep 2023 01:02:31 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40434d284f7so4142005e9.3 for ; Thu, 14 Sep 2023 01:02:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1694678550; x=1695283350; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Yy7C3eh8AGJ5bOR1d/ShKLFT+panz2pLVtrtSqm2ZHg=; b=XD76436IqKjCqyjfCqfMZRTQBNlgBe65EWcim9kOBLUT48ZwCcklXXHkGTmAMPbpqc jksJbKz3t+2dZZjifjWIBcM4bwjhOi5Btdf3uCyLW9L0fYQXlvLAUBTm7rYHs6iEYOoW 71nJ7E1Go4X5VWgwy0b3Ni7h1WIkiVyhDubUnH8NCGOJD4UiqJp2JF2PXdKoesLlVEAU 0UWyFagIjEj/7idmggSoqlQUYHcy4fnajX709YcLmwEty0uYA9eDUTa2ExxcfDiwnofO S5nmV1xcepEP77Imkro17DjGG9tClb4L9gxQh8gQusxEPsLy1cZ6DfG8YaUNdwjEmEOZ SiAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694678550; x=1695283350; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Yy7C3eh8AGJ5bOR1d/ShKLFT+panz2pLVtrtSqm2ZHg=; b=IUAl8R2A4AI0pMigY6ymuygzHZl8bKFLD1Xvqg3e2ds0B832p/+vjNnsjbCAkSeZUt 2ho1XfehgA/WYD5adh6RmSKxG2Ws3DlvtF5/TSj6yE6ee/PflnuBztMswrazWcB9YAQ7 QF4Lw0Jz3LAGv2H10Sxxk1ZU7yZdcKhGuKs0tG6hP9qi6JIlfClQ27eQxrM/Iw1UtKzq N6QUzuT38CF1bmryHcLmu7KTUkdd8tz2Nn7aPRFqet2ud8IQ97bGHU8IqJSL3xCXgViu Tv94g9WF18KiNLoBj1yzyet+Bx+tp5uaw/3Ca+ttU6z5Tb2WVvEw/C/gL4lv6kzg5kWj RM4Q== X-Gm-Message-State: AOJu0YygLdHLyaXAN34BQQsGnXMZnAN2lY1g3eKhs2bejEuPcBEuF8JF NXc0iZKndhI32LYR0BelUNXZKw== X-Google-Smtp-Source: AGHT+IG3SmBgVgZZJ5iJ7L/Ga7w0g/7ztmL7VNHiAqZIQ8zO3HOGSRNBtLv27Eam03BPW7kg9b1sOA== X-Received: by 2002:a7b:c414:0:b0:402:fe6d:6296 with SMTP id k20-20020a7bc414000000b00402fe6d6296mr4102677wmi.9.1694678550109; Thu, 14 Sep 2023 01:02:30 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id t7-20020a1c7707000000b003fedcd02e2asm1233317wmi.35.2023.09.14.01.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 01:02:29 -0700 (PDT) Date: Thu, 14 Sep 2023 10:02:28 +0200 From: Andrew Jones To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Haibo Xu , Anup Patel Subject: Re: [PATCH] KVM: selftests: Assert that vasprintf() is successful Message-ID: <20230914-d8d1bb0c3d71454c0a55f721@orel> References: <20230914010636.1391735-1-seanjc@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230914010636.1391735-1-seanjc@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 13, 2023 at 06:06:36PM -0700, Sean Christopherson wrote: > Assert that vasprintf() succeeds as the "returned" string is undefined > on failure. Checking the result also eliminates the only warning with > default options in KVM selftests, i.e. is the only thing getting in the > way of compile with -Werror. > > lib/test_util.c: In function ‘strdup_printf’: > lib/test_util.c:390:9: error: ignoring return value of ‘vasprintf’ > declared with attribute ‘warn_unused_result’ [-Werror=unused-result] > 390 | vasprintf(&str, fmt, ap); > | ^~~~~~~~~~~~~~~~~~~~~~~~ > Oh, darn. My compilers didn't report that or I would have fixed it. > Don't bother capturing the return value, allegedly vasprintf() can only > fail due to a memory allocation failure. > > Fixes: dfaf20af7649 ("KVM: arm64: selftests: Replace str_with_index with strdup_printf") > Cc: Andrew Jones > Cc: Haibo Xu > Cc: Anup Patel > Signed-off-by: Sean Christopherson > --- > > I haven't actually run the relevant tests, someone should probably do so on > ARM and/or RISC-V to make sure I didn't do something stupid. Done for both. Reviewed-by: Andrew Jones Tested-by: Andrew Jones Thanks, drew > > tools/testing/selftests/kvm/lib/test_util.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c > index 3e36019eeb4a..5d7f28b02d73 100644 > --- a/tools/testing/selftests/kvm/lib/test_util.c > +++ b/tools/testing/selftests/kvm/lib/test_util.c > @@ -387,7 +387,7 @@ char *strdup_printf(const char *fmt, ...) > char *str; > > va_start(ap, fmt); > - vasprintf(&str, fmt, ap); > + TEST_ASSERT(vasprintf(&str, fmt, ap) >= 0, "vasprintf() failed"); > va_end(ap); > > return str; > > base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d > -- > 2.42.0.283.g2d96d420d3-goog >