Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1400924rdb; Wed, 20 Sep 2023 08:10:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQdg3qn8kvueC0efGCDcijheKFOPlN1WTrKpeLXEhMyulxm29Yuh3NsCIaPCkywBKC/A6j X-Received: by 2002:aa7:8885:0:b0:690:cd6e:8d38 with SMTP id z5-20020aa78885000000b00690cd6e8d38mr2604075pfe.25.1695222601992; Wed, 20 Sep 2023 08:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695222601; cv=none; d=google.com; s=arc-20160816; b=XJygeGWb1CcAMBFZILfjYmFzwKo7T1buB2LD5TrPPymUICdAi9s9oMnIwdIYLFDEu+ jjnYtkv7WDnMic1jsm6xCERTuXYKm6iezQw/rVC5gNqn2G8m1r4tMqqwv6Lwzzr8V11p 2TYAjbmIolNcoia16fovXpN885zgKhnkZX5AjB+ChdGRfp7a3UySmQ/clWGBDjRadEPT NvmbrbH9e2MLC+ZD1l0yE8UCwgrKKhbiTtNjgZnpr2BOXFBTrRVtFbCl8q8QVjxHsSzR DE8GS9gIf5Mv7O3g2HVV7x7jcpGlRs3TSo8N/yG081Nw8IdTf7XtnstOtNAdGks5DVTz nRVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=pgZwt1T4d3hqvoQNUQ17EeQ3XSK0TCSwEQOyJOeNjhM=; fh=81QtALhg/GosUwZk7Q0gzqX++lWh9K6CF/dvjF8UR5w=; b=L6IQQJq2OGdfFJJPCOMzrClj+c5Rrl+8t46+qhEtpkWboxnoTnXKKDcXgGXWCWMAkq 9vlG9p0uxWxH6fOq28XEKn0ib+7yRLdVouUYyJ+vAbrTzPXVCG2WJe82IMr2tmAAm6b5 yROJdzyIQl4l+z4iar8O4aKb+iQq0kdVggf+sNNqHKTVc0ufk6gaTgN2mFpTQFBy6HWK 6OJ/nLC36qqGekOqMrYQvbVVK7KNnmlrQoGAQJ0VXKLqmLeiK3iV89NJ0YROXhOufSG5 q9sdoxKbBc03xPjGb8eEk+GohEJCGgxl+2NoduWYfbJ2VMBY2DE55TJsTSf4x/jmMEL0 e/VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=DnPrnIJe; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id j22-20020a056a00235600b0069026a3de0asi12187218pfj.138.2023.09.20.08.10.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:10:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=DnPrnIJe; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 7808F806E3CD; Wed, 20 Sep 2023 01:42:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233349AbjITImc (ORCPT + 99 others); Wed, 20 Sep 2023 04:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233714AbjITIma (ORCPT ); Wed, 20 Sep 2023 04:42:30 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B07893; Wed, 20 Sep 2023 01:42:21 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B5B7022476; Wed, 20 Sep 2023 08:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695199339; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pgZwt1T4d3hqvoQNUQ17EeQ3XSK0TCSwEQOyJOeNjhM=; b=DnPrnIJeqRiZu04zLpzzJdvXZs85anv9N55kSKe4KevOMka/Z3Db/X4CWlXgVgCaXM0Gax mk8lNcu6iIsvjYuEwOH99zYKL2pe0+jEjZKk7JQ6gVcud7gQvta2K/sd8lJ+270a79lK8j 53cnpNpNSKuVlwFKF1O/Q514y7qQoZY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695199339; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=pgZwt1T4d3hqvoQNUQ17EeQ3XSK0TCSwEQOyJOeNjhM=; b=kTHnCRY2vVNXTDOfIKdsXnboCL/f4BXoyBcZA5SeIq0/xa5N7jBxpxv5jnHIhhVKW8S98M ZH3yksLM2yM8kOAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 76F26132C7; Wed, 20 Sep 2023 08:42:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4xEJHGuwCmWSXAAAMHmgww (envelope-from ); Wed, 20 Sep 2023 08:42:19 +0000 Date: Wed, 20 Sep 2023 10:42:18 +0200 Message-ID: <87o7hxutg5.wl-tiwai@suse.de> From: Takashi Iwai To: Richard Fitzgerald Cc: Nick Desaulniers , , , , , , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Subject: Re: [PATCH 2/2] ALSA: hda: cirrus_scodec: Add KUnit test In-Reply-To: <9e2291c1-9a6c-ba6b-ea0f-ad130d2596f4@opensource.cirrus.com> References: <20230918095129.440-1-rf@opensource.cirrus.com> <20230918095129.440-3-rf@opensource.cirrus.com> <874jjpwd4i.wl-tiwai@suse.de> <9e2291c1-9a6c-ba6b-ea0f-ad130d2596f4@opensource.cirrus.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 20 Sep 2023 01:42:37 -0700 (PDT) On Wed, 20 Sep 2023 10:27:58 +0200, Richard Fitzgerald wrote: > > On 20/9/23 07:51, Takashi Iwai wrote: > > On Tue, 19 Sep 2023 22:44:28 +0200, > > Nick Desaulniers wrote: > >> > >> On Mon, Sep 18, 2023 at 10:51:29AM +0100, Richard Fitzgerald wrote: > > (snip) > >>> +static void cirrus_scodec_test_set_gpio_ref_arg(struct software_node_ref_args *arg, > >>> + int gpio_num) > >>> +{ > >>> + struct software_node_ref_args template = > >>> + SOFTWARE_NODE_REFERENCE(&cirrus_scodec_test_gpio_swnode, gpio_num, 0); > >> > >> I'm observing the following error when building with: > >> > >> $ make LLVM=1 -j128 allmodconfig sound/pci/hda/cirrus_scodec_test.o > >> > >> sound/pci/hda/cirrus_scodec_test.c:151:60: error: initializer element is not a compile-time constant > >> 151 | SOFTWARE_NODE_REFERENCE(&cirrus_scodec_test_gpio_swnode, gpio_num, 0); > >> | ^~~~~~~~ > >> /builds/linux/include/linux/property.h:291:37: note: expanded from macro 'SOFTWARE_NODE_REFERENCE' > >> 291 | .nargs = ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1, \ > >> | ^~~~~~~~~~~ > >> /builds/linux/include/linux/kernel.h:57:75: note: expanded from macro 'ARRAY_SIZE' > >> 57 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) > >> | ^~~ > >> /builds/linux/include/linux/compiler.h:228:59: note: expanded from macro '__must_be_array' > >> 228 | #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) > >> | ^ > >> /builds/linux/include/linux/compiler_types.h:366:63: note: expanded from macro '__same_type' > >> 366 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) > >> | ^ > >> /builds/linux/include/linux/build_bug.h:16:62: note: expanded from macro 'BUILD_BUG_ON_ZERO' > >> 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) > >> | ^ > > > > Hm, this looks like some inconsistent handling of the temporary array > > passed to ARRAY_SIZE() in the SOFTWARE_NODE_REFERENCE macro. LLVM > > can't treat it if it contains a variable in the given array, while GCC > > doesn't care. > > > > A hackish workaround would be the patch like below, but it's really > > ugly. Ideally speaking, it should be fixed in linux/properties.h, but > > I have no idea how to fix there for LLVM. > > > > Adding more relevant people to Cc. > > > > > > thanks, > > > > Takashi > > > > --- a/sound/pci/hda/cirrus_scodec_test.c > > +++ b/sound/pci/hda/cirrus_scodec_test.c > > @@ -148,8 +148,9 @@ static void cirrus_scodec_test_set_gpio_ref_arg(struct software_node_ref_args *a > > int gpio_num) > > { > > struct software_node_ref_args template = > > - SOFTWARE_NODE_REFERENCE(&cirrus_scodec_test_gpio_swnode, gpio_num, 0); > > + SOFTWARE_NODE_REFERENCE(&cirrus_scodec_test_gpio_swnode, 0, 0); > > + template.args[0] = gpio_num; > > *arg = template; > > } > > > > The tests must generate sw nodes dynamically, not a fixed const struct. > I wanted to avoid directly accessing the internals of the SW node > structures. Use only the macros. > > I can rewrite this code to open-code the construction of the > software_node_ref_args. Or I can wait a while in case anyone has a > suggested fix for the macros. > > Its seems reasonable that you should be able to create software nodes > dynamically. A "real" use of these might need to construct the data from > some other data that is not known at runtime (for example, where the > ACPI provides some information but not the necessary info). Yeah, fixing the macro would be ideal. An easy and compromise solution would be to factor out the ARRAY_SIZE() call and allow giving nargs explicitly. e.g. --- a/include/linux/property.h +++ b/include/linux/property.h @@ -285,13 +285,18 @@ struct software_node_ref_args { u64 args[NR_FWNODE_REFERENCE_ARGS]; }; -#define SOFTWARE_NODE_REFERENCE(_ref_, ...) \ +#define __SOFTWARE_NODE_REFERENCE(_ref_, _nargs_, ...) \ (const struct software_node_ref_args) { \ .node = _ref_, \ - .nargs = ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1, \ + .nargs = _nargs_, \ .args = { __VA_ARGS__ }, \ } +#define SOFTWARE_NODE_REFERENCE(_ref_, ...) \ + __SOFTWARE_NODE_REFERENCE(_ref_,\ + ARRAY_SIZE(((u64[]){ 0, ##__VA_ARGS__ })) - 1,\ + ##__VA_ARGS__) + /** * struct property_entry - "Built-in" device property representation. * @name: Name of the property. --- a/sound/pci/hda/cirrus_scodec_test.c +++ b/sound/pci/hda/cirrus_scodec_test.c @@ -148,7 +148,7 @@ static void cirrus_scodec_test_set_gpio_ref_arg(struct software_node_ref_args *a int gpio_num) { struct software_node_ref_args template = - SOFTWARE_NODE_REFERENCE(&cirrus_scodec_test_gpio_swnode, gpio_num, 0); + __SOFTWARE_NODE_REFERENCE(&cirrus_scodec_test_gpio_swnode, 2, gpio_num, 0); *arg = template; } ... though I'm not convinced by this change, either. Takashi