Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp112621lqb; Tue, 4 Jun 2024 06:42:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU76wxfeHk4YrryZcBsNGo1r92sA3REL4V8pBaNoKQ6V6cX+VjPGP93jHlqPo5iBA6UvT8tdcT4lbEUGMYqK0+dt4m6Cr4zVsABqBWO6w== X-Google-Smtp-Source: AGHT+IH3Yn+A6ivoXIojalGbRI09Wy56pu6EJzwge3eGNov9PXJIIbJjLX61DMh+bl0js5fteekF X-Received: by 2002:a05:6870:e9a9:b0:250:866c:5bda with SMTP id 586e51a60fabf-2508bdd726fmr12151866fac.24.1717508548419; Tue, 04 Jun 2024 06:42:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717508548; cv=pass; d=google.com; s=arc-20160816; b=wVQOI08obF6hNLcjav3c3N8cANw/UcGsJ0+HU3+KuQ0bATJVBP0qpMTkl3xuivhgbt XFbxSa+VpKH5XwplmzAbGySqZKYStRz1bPDogBO+gFRSbP1jQ+1LIFo4PlJSQSXMysMp aSL0eS9r5oVxOomikbq7A6RDF1F7bftxCj4kZvI0tx1AkztnSTKsMCwbEZQCM2sEIArN U09W1FdY2UiHVZhAxvTXbHjrlGdLIN6i2DhNjFWxhnkVIelYkIS7HLxYcLk70G4tNxde QpMNN9Trj6a0N4ePu0TV05UK74QwPes/qyooUL2Y/i8ZL63UHbh5LSyCHd/Vjo9LWipU 0uYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NLx9D3E/f7ZlDsKhaFbep7Z/zSniFAeZ0uaVtAKC8Rs=; fh=uyYkCcKSM4oBbywEdMU63RNaDZXQ4E1EbEk8Qmol9oY=; b=Zsr7RW9qxpdnvqspXP/6iXkbAhpOdEYDsgG1p9G2W7meGBxMzy4xZfY6kaTtdHcP4y Xi20UxmxzxkgbSUyOALTlWs/LRFeJqYjcGOaHiRtgSbR1CSI2JTll5hlCVbw8qGKJlcD 0uAvLw2eb1A2VLiG8X5OUZLEnwzNj2isZRKvmSb4sKI/KdYacrxFLa8NFUL9LBCr9SN7 NH+GAWaFFKPmUHLY+wIejKJcIYZkXbKbSo11sq6igiBuT7zkILNkEC6kykARW7fLvjE3 X4rAGBaa0K30wOg75dN6aAsgyMbfwovkmrnxXKc9NODrP8rMXxQagEpFgbhpF+XPmP/A OF6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bXYkUdIM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4685-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4685-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-7951af75097si110026685a.205.2024.06.04.06.42.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 06:42:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4685-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bXYkUdIM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4685-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4685-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 168D81C21378 for ; Tue, 4 Jun 2024 13:42:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7A1D148826; Tue, 4 Jun 2024 13:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bXYkUdIM" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC382148300; Tue, 4 Jun 2024 13:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717508492; cv=none; b=jWHhiAegQiwPDlrFtlMFdNOomSeQpYvtgP6YEYbafr4xSFZ8JIdo56RQfohyWzPZTi+E/UvUp+x3J4vWovziN+W95/Hv3ZmOvdCpDf6o9eqOWhIsXkf1oKIim/uNpH/ARXVnT/Ed7xPG5r2M2cu4e2eSl7cqqmcnXaDENYuuCEg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717508492; c=relaxed/simple; bh=FArcXwplL8wN1ALhCuGpUD+BoCuPOB8+aNe29ijJswU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZeRJ2qvcoFeWuP8tj3Ghd6tq/ax4CdaOGoLw+6/qWX8WcClN85JUMC8LYvqHwEoQY+sXRsY2z+kg6B97KsWFjBsi81qs2XlysFIAeP5LCQOnj8am51OPFnwJyImIQpp0s8T05xB7xMwWo04Erm24GsnJ7XPTWcZFy/RgrLRaHW8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bXYkUdIM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BE38C2BBFC; Tue, 4 Jun 2024 13:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717508491; bh=FArcXwplL8wN1ALhCuGpUD+BoCuPOB8+aNe29ijJswU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bXYkUdIM5G5RAUoPD7MJYr//S1oqHl+LJ3fxfw7lfSFuBw8JhGTBW9PLufCUqHKjY OJVFk7K+rOrq9HuH76qkiJL0A/sTi2rTQodn+TKkQocB/tbQHZeZKu3m3G2lM5wcf0 VD97GRCGMBes8MaOHcg8KM5fvFeye/FAQg9SKZN6tpIn5+9U5FE+VZJf0uRZu8AxbF xrs4Rlqn5YOUS7D0btNT9APFrOK0n1Q8HZ/ji58Sj2kGEhPit3yyT7IaR0HjrbKKbe 82WAiCP1NrKaOO3384inkZ8fhbN5SYnrWSCyMgS7pEXOOMKSO77chS2wlgGdCmIr5c AAtt4MysOip3g== Date: Tue, 4 Jun 2024 14:41:26 +0100 From: Andi Shyti To: Andy Shevchenko Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , Corey Minyard , Allen Pais , Sebastian Reichel , Perry Yuan , Giovanni Cabiddu , Herbert Xu , Nuno Sa , Guenter Roeck , Randy Dunlap , Heiner Kallweit , Lee Jones , Samuel Holland , Elad Nachman , Arseniy Krasnov , Johannes Berg , Gregory Greenman , Benjamin Berg , Bjorn Helgaas , Robert Richter , Vinod Koul , Chunfeng Yun , Linus Walleij , Hans de Goede , Ilpo =?utf-8?B?SsOkcnZpbmVu?= , Nikita Kravets , Jiri Slaby , Srinivas Pandruvada , Stanley Chang , Heikki Krogerus , Abdel Alkuor , Kent Overstreet , Eric Biggers , Kees Cook , Ingo Molnar , "Steven Rostedt (Google)" , Daniel Bristot de Oliveira , Andrew Morton , Hugh Dickins , Abel Wu , John Johansen , Mimi Zohar , Stefan Berger , Roberto Sassu , Eric Snowberg , Takashi Iwai , Takashi Sakamoto , Jiapeng Chong , Mark Brown , Kuninori Morimoto , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, linux-acpi@vger.kernel.org, linux-ide@vger.kernel.org, openipmi-developer@lists.sourceforge.net, linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-tegra@vger.kernel.org, linux-pm@vger.kernel.org, qat-linux@intel.com, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-hwmon@vger.kernel.org, linux-i2c@vger.kernel.org, linux-leds@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-omap@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-pci@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-phy@lists.infradead.org, linux-gpio@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-staging@lists.linux.dev, linux-usb@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-hardening@vger.kernel.org, cgroups@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Naveen N. Rao" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , David Howells , "David S. Miller" , "Rafael J. Wysocki" , Len Brown , Sergey Shtylyov , Damien Le Moal , Niklas Cassel , Daniel Scally , Sakari Ailus , Michael Turquette , Stephen Boyd , Florian Fainelli , Ray Jui , Scott Branden , Broadcom internal kernel review list , Heiko Stuebner , Peter De Schrijver , Prashant Gaikwad , Thierry Reding , Jonathan Hunter , Huang Rui , "Gautham R. Shenoy" , Mario Limonciello , Viresh Kumar , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jani Nikula , Rodrigo Vivi , Joonas Lahtinen , Tvrtko Ursulin , Karol Herbst , Lyude Paul , Danilo Krummrich , Jean Delvare , Alexander Shishkin , Pavel Machek , Chen-Yu Tsai , Jernej Skrabec , Tony Lindgren , Adrian Hunter , Hu Ziji , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Potnuri Bharat Teja , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Miri Korenblit , Kalle Valo , Mahesh J Salgaonkar , Oliver O'Halloran , Kishon Vijay Abraham I , Matthias Brugger , AngeloGioacchino Del Regno , JC Kuo , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Sebastian Reichel , Daniel Lezcano , Zhang Rui , Lukasz Luba , Thinh Nguyen , Helge Deller , Brian Foster , Zhihao Cheng , Tejun Heo , Zefan Li , Johannes Weiner , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Masami Hiramatsu , Mathieu Desnoyers , Jason Baron , Jim Cromie , Paul Moore , James Morris , "Serge E. Hallyn" , Dmitry Kasatkin , Clemens Ladisch , Jaroslav Kysela , Takashi Iwai , Liam Girdwood , Linus Torvalds Subject: Re: [PATCH v1 1/1] treewide: Align match_string() with sysfs_match_string() Message-ID: <3ojs6btxgava4dcasys5tnrg5vsrqlshagcg7otvrdgfcwwje4@lcrd3r6gkfcs> References: <20240603211538.289765-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240603211538.289765-1-andriy.shevchenko@linux.intel.com> Hi Andy, On Sun, Jun 02, 2024 at 06:57:12PM +0300, Andy Shevchenko wrote: > Make two APIs look similar. Hence convert match_string() to be > a 2-argument macro. In order to avoid unneeded churn, convert > all users as well. There is no functional change intended. > > Signed-off-by: Andy Shevchenko nice patch, I checked some (maybe most) of your changes. There are a few unrelated changes which I don't mind, but there are two errors where the error value changes from ENODEV to EINVAL. Find the comments through the line. ... > diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c > index 1b7e82a0ad2e..b6f52f44625f 100644 > --- a/drivers/cpufreq/amd-pstate.c > +++ b/drivers/cpufreq/amd-pstate.c > @@ -1117,9 +1117,9 @@ static ssize_t store_energy_performance_preference( > if (ret != 1) > return -EINVAL; > > - ret = match_string(energy_perf_strings, -1, str_preference); > + ret = __match_string(energy_perf_strings, -1, str_preference); > if (ret < 0) > - return -EINVAL; > + return ret; a bit of unrelated changes here, but I guess no one will complain :-) > > mutex_lock(&amd_pstate_limits_lock); > ret = amd_pstate_set_energy_pref_index(cpudata, ret); ... > diff --git a/drivers/mmc/host/sdhci-xenon-phy.c b/drivers/mmc/host/sdhci-xenon-phy.c > index cc9d28b75eb9..1865e26ae736 100644 > --- a/drivers/mmc/host/sdhci-xenon-phy.c > +++ b/drivers/mmc/host/sdhci-xenon-phy.c > @@ -135,15 +135,14 @@ struct xenon_emmc_phy_regs { > u32 logic_timing_val; > }; > > -static const char * const phy_types[] = { > - "emmc 5.0 phy", > - "emmc 5.1 phy" > -}; > - > enum xenon_phy_type_enum { > EMMC_5_0_PHY, > EMMC_5_1_PHY, > - NR_PHY_TYPES > +}; > + > +static const char * const phy_types[] = { > + [EMMC_5_0_PHY] = "emmc 5.0 phy", > + [EMMC_5_1_PHY] = "emmc 5.1 phy", > }; Another unrelated cleanup, but I don't complain > enum soc_pad_ctrl_type { ... > - tablet_found = match_string(tablet_chassis_types, > - ARRAY_SIZE(tablet_chassis_types), > - chassis_type) >= 0; > - if (!tablet_found) > - return -ENODEV; > + ret = match_string(tablet_chassis_types, chassis_type); > + if (ret < 0) > + return ret; This is a logical change though, because we are changing from -ENODEV to -EINVAL. Even if it might look the right thing, but still, it's a logical change. > > ret = hp_wmi_perform_query(HPWMI_SYSTEM_DEVICE_MODE, HPWMI_READ, > system_device_mode, zero_if_sup(system_device_mode), > @@ -490,9 +487,7 @@ static bool is_omen_thermal_profile(void) > if (!board_name) > return false; > > - return match_string(omen_thermal_profile_boards, > - ARRAY_SIZE(omen_thermal_profile_boards), > - board_name) >= 0; > + return match_string(omen_thermal_profile_boards, board_name) >= 0; > } > > static int omen_get_thermal_policy_version(void) ... > diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c > index e56db75a94fb..dbd176b0fb1f 100644 > --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c > +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c > @@ -111,7 +111,7 @@ static ssize_t suffix##_show(struct device *dev,\ > match_strs = (const char **)fivr_strings;\ > mmio_regs = tgl_fivr_mmio_regs;\ > } \ > - ret = match_string(match_strs, -1, attr->attr.name);\ > + ret = __match_string(match_strs, -1, attr->attr.name);\ > if (ret < 0)\ > return ret;\ > reg_val = readl((void __iomem *) (proc_priv->mmio_base + mmio_regs[ret].offset));\ > @@ -145,7 +145,7 @@ static ssize_t suffix##_store(struct device *dev,\ > mmio_regs = tgl_fivr_mmio_regs;\ > } \ > \ > - ret = match_string(match_strs, -1, attr->attr.name);\ > + ret = __match_string(match_strs, -1, attr->attr.name);\ > if (ret < 0)\ > return ret;\ > if (mmio_regs[ret].read_only)\ > diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c > index f298e7442662..57f456befb34 100644 > --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c > +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_req.c > @@ -50,7 +50,7 @@ static ssize_t workload_type_store(struct device *dev, > if (ret != 1) > return -EINVAL; > > - ret = match_string(workload_types, -1, str_preference); > + ret = __match_string(workload_types, -1, str_preference); We could even thing of a "match_string_terminated" (or a better name), but maybe it's too much? > if (ret < 0) > return ret; > ... > - c->auth_hash_algo = match_string(hash_algo_name, HASH_ALGO__LAST, > - c->auth_hash_name); > - if ((int)c->auth_hash_algo < 0) { > + err = __match_string(hash_algo_name, HASH_ALGO__LAST, c->auth_hash_name); > + if (err < 0) { > ubifs_err(c, "Unknown hash algo %s specified", > c->auth_hash_name); > - return -EINVAL; > + return err; This is correct! > } > + c->auth_hash_algo = err; > > snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)", > c->auth_hash_name); ... > +int __match_string(const char * const *array, size_t n, const char *string); > + > +/** > + * match_string - matches given string in an array > + * @_a: array of strings > + * @_s: string to match with > + * > + * Helper for __match_string(). Calculates the size of @a automatically. /@a/@_a/ > + */ > +#define match_string(_a, _s) __match_string(_a, ARRAY_SIZE(_a), _s) > + ... > diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c > index 6239777090c4..e3fc94b4c7e5 100644 > --- a/security/apparmor/lsm.c > +++ b/security/apparmor/lsm.c > @@ -1820,9 +1820,9 @@ static int param_set_audit(const char *val, const struct kernel_param *kp) > if (apparmor_initialized && !aa_current_policy_admin_capable(NULL)) > return -EPERM; > > - i = match_string(audit_mode_names, AUDIT_MAX_INDEX, val); > + i = __match_string(audit_mode_names, AUDIT_MAX_INDEX, val); pity here... this could have been a match_string, but the MAX_INDEX is hardcoded outside the enum. > if (i < 0) > - return -EINVAL; > + return i; > > aa_g_audit = i; > return 0; ... > diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c > index 16dad4a45443..7064f4cae549 100644 > --- a/sound/soc/soc-dapm.c > +++ b/sound/soc/soc-dapm.c > @@ -769,14 +769,13 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, > item = 0; > } > > - i = match_string(e->texts, e->items, control_name); > + i = __match_string(e->texts, e->items, control_name); > if (i < 0) > - return -ENODEV; > + return i; Also this return value is wrong. Andi > > path->name = e->texts[i]; > path->connect = (i == item); > return 0; > - > } > > /* set up initial codec paths */ > -- > 2.43.0.rc1.1336.g36b5255a03ac >