From nobody Tue Sep 9 21:36:13 2025 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 A13EEC7EE2F for ; Wed, 1 Mar 2023 15:22:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230318AbjCAPWv (ORCPT ); Wed, 1 Mar 2023 10:22:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjCAPWq (ORCPT ); Wed, 1 Mar 2023 10:22:46 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C7E043468; Wed, 1 Mar 2023 07:22:44 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id AF9D160012; Wed, 1 Mar 2023 15:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D5n3KQw5FkYOO2ZCdrhHgke1RNc7JrIvX3lBsallp24=; b=Kj2GBS6PPrHijhJPSkrA4vv0KT5OEQjjPzF/nW8BXycugB6Xu2gjOknzG/damIwd2TRanB 1c0enPgMMA8IIszMLk2A2lUxLYou1ZnsNAfPMRSq9UfHRxc2P9tFLXj26oYAbc4GVC4eQN 0KNTTxCFwb+Q76V4T85IG3UhO47piXTUvwK3hJ6FwBGavwT29CLzVbM9dOuJFJb2ToXDjr OTrUQwOkQ2BRS77IXkpqxx9cxjVlAmOP0CcazAKndeBIaTnOp8cdYqdh8H2EI2dOp0YE4J 1zW8buw6ZSfccyYSDnVdkAZpjvXYOopBMxsVq0Sh06xby1+8nOpZXdumZuoSWQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal , Stephen Boyd , Peter Chen Subject: [PATCH 1/8] of: Fix modalias string generation Date: Wed, 1 Mar 2023 16:22:32 +0100 Message-Id: <20230301152239.531194-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The helper generating an OF based modalias (of_device_get_modalias()) works fine, but due to the use of snprintf() internally it needs a buffer one byte longer than what should be needed just for the entire string (excluding the '\0'). Most users of this helper are sysfs hooks providing the modalias string to users. They all provide a PAGE_SIZE buffer which is way above the number of bytes required to fit the modalias string and hence do not suffer from this issue. There is another user though, of_device_request_module(), which is only called by drivers/usb/common/ulpi.c. This request module function is faulty, but maybe because in most cases there is an alternative, ULPI driver users have not noticed it. In this function, of_device_get_modalias() is called twice. The first time without buffer just to get the number of bytes required by the modalias string (excluding the null byte), and a second time, after buffer allocation, to fill the buffer. The allocation asks for an additional byte, in order to store the trailing '\0'. However, the buffer *length* provided to of_device_get_modalias() excludes this extra byte. The internal use of snprintf() with a length that is exactly the number of bytes to be written has the effect of using the last available byte to store a '\0', which then smashes the last character of the modalias string. Provide the actual size of the buffer to of_device_get_modalias() to fix this issue. Note: the "str[size - 1] =3D '\0';" line is not really needed as snprintf will anyway end the string with a null byte, but there is a possibility that this function might be called on a struct device_node without compatible, in this case snprintf() would not be executed. So we keep it just to avoid possible unbounded strings. Cc: Stephen Boyd Cc: Peter Chen Fixes: 9c829c097f2f ("of: device: Support loading a module with OF based mo= dalias") Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring Tested-by: Michael Walle --- drivers/of/device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index c674a13c3055..877f50379fab 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -297,12 +297,15 @@ int of_device_request_module(struct device *dev) if (size < 0) return size; =20 - str =3D kmalloc(size + 1, GFP_KERNEL); + /* Reserve an additional byte for the trailing '\0' */ + size++; + + str =3D kmalloc(size, GFP_KERNEL); if (!str) return -ENOMEM; =20 of_device_get_modalias(dev, str, size); - str[size] =3D '\0'; + str[size - 1] =3D '\0'; ret =3D request_module(str); kfree(str); =20 --=20 2.34.1 From nobody Tue Sep 9 21:36:13 2025 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 5EE30C7EE33 for ; Wed, 1 Mar 2023 15:23:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjCAPXF (ORCPT ); Wed, 1 Mar 2023 10:23:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbjCAPWs (ORCPT ); Wed, 1 Mar 2023 10:22:48 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C801A43913; Wed, 1 Mar 2023 07:22:45 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 195366000E; Wed, 1 Mar 2023 15:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+7AJrEMliVgBGap4LkX/HwlJ+8DgiboSpzHjInCtEXM=; b=IQjaQf6SnB4xzp2ZcsKZdwwmYbgP6zO+qx9MDcHhTY3LB0uttv5GFdaJ10fIpeEOkXtuxc O8iwOHhZFYR0+rdGC2DcMefWDub/i3h1R059kyct7yg8dNOUphv8MGq9S7RMF0v18AkUXR 3ABsklzeBxg6psCn/3Q+akkRUFSjd0Lyp4+uaB9opG6Up6/IKSNv+OUGjR6KuPQHhW65Wu rmkqR4GiSQanxQqvGs683wK8blJec9eqdlSNM6K+GJKL2Z1EeOuU1w2v78H8PADr/C5Kej m8BHqEp5TdUtujborz+WU5IJ/NuiZrHaHYLMvvIkqI1hbh62YNL1yVHz6F/GqQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 2/8] of: Change of_device_get_modalias() main argument Date: Wed, 1 Mar 2023 16:22:33 +0100 Message-Id: <20230301152239.531194-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This function needs "struct device_node" to work, but for convenience the author and only user of this helper did use a "struct device". As this helper is a static helper, let's keep the "struct device" for exported methods and use the OF structure internally. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/of/device.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 877f50379fab..3efc17de1d57 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -248,7 +248,7 @@ const void *of_device_get_match_data(const struct devic= e *dev) } EXPORT_SYMBOL(of_device_get_match_data); =20 -static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize= _t len) +static ssize_t of_device_get_modalias(struct device_node *np, char *str, s= size_t len) { const char *compat; char *c; @@ -256,19 +256,16 @@ static ssize_t of_device_get_modalias(struct device *= dev, char *str, ssize_t len ssize_t csize; ssize_t tsize; =20 - if ((!dev) || (!dev->of_node)) - return -ENODEV; - /* Name & Type */ /* %p eats all alphanum characters, so %c must be used here */ - csize =3D snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T', - of_node_get_device_type(dev->of_node)); + csize =3D snprintf(str, len, "of:N%pOFn%c%s", np, 'T', + of_node_get_device_type(np)); tsize =3D csize; len -=3D csize; if (str) str +=3D csize; =20 - of_property_for_each_string(dev->of_node, "compatible", p, compat) { + of_property_for_each_string(np, "compatible", p, compat) { csize =3D strlen(compat) + 1; tsize +=3D csize; if (csize > len) @@ -293,7 +290,10 @@ int of_device_request_module(struct device *dev) ssize_t size; int ret; =20 - size =3D of_device_get_modalias(dev, NULL, 0); + if (!dev || !dev->of_node) + return -ENODEV; + + size =3D of_device_get_modalias(dev->of_node, NULL, 0); if (size < 0) return size; =20 @@ -304,7 +304,7 @@ int of_device_request_module(struct device *dev) if (!str) return -ENOMEM; =20 - of_device_get_modalias(dev, str, size); + of_device_get_modalias(dev->of_node, str, size); str[size - 1] =3D '\0'; ret =3D request_module(str); kfree(str); @@ -321,7 +321,12 @@ EXPORT_SYMBOL_GPL(of_device_request_module); */ ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len) { - ssize_t sl =3D of_device_get_modalias(dev, str, len - 2); + ssize_t sl; + + if ((!dev) || (!dev->of_node)) + return -ENODEV; + + sl =3D of_device_get_modalias(dev->of_node, str, len - 2); if (sl < 0) return sl; if (sl > len - 2) @@ -386,7 +391,7 @@ int of_device_uevent_modalias(struct device *dev, struc= t kobj_uevent_env *env) if (add_uevent_var(env, "MODALIAS=3D")) return -ENOMEM; =20 - sl =3D of_device_get_modalias(dev, &env->buf[env->buflen-1], + sl =3D of_device_get_modalias(dev->of_node, &env->buf[env->buflen-1], sizeof(env->buf) - env->buflen); if (sl >=3D (sizeof(env->buf) - env->buflen)) return -ENOMEM; --=20 2.34.1 From nobody Tue Sep 9 21:36:13 2025 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 9E013C64ED6 for ; Wed, 1 Mar 2023 15:22:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjCAPW5 (ORCPT ); Wed, 1 Mar 2023 10:22:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbjCAPWt (ORCPT ); Wed, 1 Mar 2023 10:22:49 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F75C3BD86; Wed, 1 Mar 2023 07:22:46 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 4B3AC6000A; Wed, 1 Mar 2023 15:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=20ZNMpm9x0asQsEVva+trdnvABlBWfMLwEchVbLYbKo=; b=cRlym06tZywCTPZhMhhv3ejIASwMs5VLbcTsNBcHZ3o0jWWg0M9dCON5Yyx7mCgKEEPUtb RWFM72XRkmW45Igkq0jpfvDReypUSHR1o6ArajPEmtayJbqooqqoEucsZRRVBrXt1BbNrE dKj71kyVTXwuamyI2hKY2o331MivzHDWKD98BLIvQGjFQDE44ICEziO0vTaa5nbYk3uTNF Ht3R5I4MWq4GqVskw9ng7H8XJEO8ZBbvzKJ/cNvXHBMi7cFrgsQ17uY0WcW1+9Ltszx6f3 2oBlyP8hBNBPSFC80N3wawL/UQb1t4FXHYtzWpwKLPjoKM9Pk1rd2Vvo483buQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 3/8] of: Create an of_device_request_module() receiving an OF node Date: Wed, 1 Mar 2023 16:22:34 +0100 Message-Id: <20230301152239.531194-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" of_device_request_module() currently receives a "struct device" as main argument, but the only use of this pointer is to access its .of_node member. In practice, this function only needs a "struct device_node". Let's move the logic into another helper which would receive a "struct device_node" instead, and use that new helper from the ancient of_device_request_module(). Exporting this new function will be useful to request module loading when the "struct device" is not available. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/of/device.c | 17 +++++++++++++---- include/linux/of_device.h | 6 ++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 3efc17de1d57..7cdf252b9526 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -284,16 +284,16 @@ static ssize_t of_device_get_modalias(struct device_n= ode *np, char *str, ssize_t return tsize; } =20 -int of_device_request_module(struct device *dev) +int of_device_node_request_module(struct device_node *np) { char *str; ssize_t size; int ret; =20 - if (!dev || !dev->of_node) + if (!np) return -ENODEV; =20 - size =3D of_device_get_modalias(dev->of_node, NULL, 0); + size =3D of_device_get_modalias(np, NULL, 0); if (size < 0) return size; =20 @@ -304,13 +304,22 @@ int of_device_request_module(struct device *dev) if (!str) return -ENOMEM; =20 - of_device_get_modalias(dev->of_node, str, size); + of_device_get_modalias(np, str, size); str[size - 1] =3D '\0'; ret =3D request_module(str); kfree(str); =20 return ret; } +EXPORT_SYMBOL_GPL(of_device_node_request_module); + +int of_device_request_module(struct device *dev) +{ + if (!dev) + return -ENODEV; + + return of_device_node_request_module(dev->of_node); +} EXPORT_SYMBOL_GPL(of_device_request_module); =20 /** diff --git a/include/linux/of_device.h b/include/linux/of_device.h index ab7d557d541d..8918f9071ffb 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -33,6 +33,7 @@ extern void of_device_unregister(struct platform_device *= ofdev); extern const void *of_device_get_match_data(const struct device *dev); =20 extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t l= en); +extern int of_device_node_request_module(struct device_node *np); extern int of_device_request_module(struct device *dev); =20 extern void of_device_uevent(const struct device *dev, struct kobj_uevent_= env *env); @@ -78,6 +79,11 @@ static inline int of_device_modalias(struct device *dev, return -ENODEV; } =20 +static inline int of_device_node_request_module(struct device_node *np) +{ + return -ENODEV; +} + static inline int of_device_request_module(struct device *dev) { return -ENODEV; --=20 2.34.1 From nobody Tue Sep 9 21:36:13 2025 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 2DE14C64ED6 for ; Wed, 1 Mar 2023 15:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230341AbjCAPXB (ORCPT ); Wed, 1 Mar 2023 10:23:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbjCAPWt (ORCPT ); Wed, 1 Mar 2023 10:22:49 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCC3C410A4; Wed, 1 Mar 2023 07:22:47 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 6BDA560010; Wed, 1 Mar 2023 15:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1dh6uGZ61Q7do467wqoDaMh6uB2u9srGrh1AVvKSU6M=; b=VtSYrdBhwFAsMBULAFTYUYpOylcY4XED6Sw6J05beW6Q6pl0XGnYueudCn2JsgvgwiD7Bn J2vlIaTBeDzoBn73VzLTlszWkGkXD9XmvFTTj4cvyNOEmt769lODpdud+WqANq2iOt5Pkm kSZnQozL5PPeKmmUFm52qGZcR0M7cfXxSgwjY65axGIRxyZZziuL7dfjJ0DjJjxyGw/HHB OjGHqCGZPaloeHK5zTxGUBN5eZHFQDmZzJaPSadRdxcdTU8V9YppexKBcwNRQKLPRYtf+5 qyiCIR6wemROamDlR68biNhH2W3OsTU0hvxpbOetLMib/ZKxsGpWkPlBj//OwQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 4/8] nvmem: core: Fix error path ordering Date: Wed, 1 Mar 2023 16:22:35 +0100 Message-Id: <20230301152239.531194-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The layout is being retrieved before the addition of nvmem cells and after the creation of the sysfs entries. Soon the layout operation will have the possibility to fail, hence adding a new goto label in the error path. Before doing so, we need to fix the operation order in the error path. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 56b4b20a95a9..16044377a41d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -975,9 +975,9 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) =20 err_remove_cells: nvmem_device_remove_all_cells(nvmem); + nvmem_layout_put(nvmem->layout); if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); - nvmem_layout_put(nvmem->layout); err_put_device: put_device(&nvmem->dev); =20 --=20 2.34.1 From nobody Tue Sep 9 21:36:13 2025 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 0DAE9C7EE2F for ; Wed, 1 Mar 2023 15:23:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230362AbjCAPXI (ORCPT ); Wed, 1 Mar 2023 10:23:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbjCAPWu (ORCPT ); Wed, 1 Mar 2023 10:22:50 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E649442BD9; Wed, 1 Mar 2023 07:22:48 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 9DD6960013; Wed, 1 Mar 2023 15:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuIzUxO4lQXjU9mkGsm3TUZaxNfzhaCKElzogF6isV0=; b=fMXMYqkWJ3UjHLEh6WJlxZ/yVh1q0t2kjD0aviSY8eAz9MuvL53UfdXKX4S4xAwjSWfFNn sDrjZT/U5TPdJ7Eqc4rmRZiV8pM23fZbc4f2RY5cI59HOAp3BT7Psti1VTHB69Un/OKV+K DZE/pfCJLZMu/u7aKcd3Odj9nOZpNB/EPouA4si1lgYNw4M/JAi/MrmLmDHo69R3OA3Wcd O6a/tnNE0E7IoAB7wBhUX+uNvWDi12uTYaeKoc2kLL3cNxS4W2VmCO8TAng9J4+XFUEUkF VFwRQ0JVRVsFIKrDgcViHCC763rFlu06DgIttgms+3/LrHjGduUhjt/iFTwbQg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 5/8] nvmem: core: Handle the absence of expected layouts Date: Wed, 1 Mar 2023 16:22:36 +0100 Message-Id: <20230301152239.531194-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout is not available. This condition cannot be triggered today as nvmem layout drivers are initialed as part of an early init call, but soon these drivers will be converted into modules and be initialized with a standard priority, so the unavailability of the drivers might become a reality that must be taken care of. Let's anticipate this by telling the caller the layout might not yet be available. A probe deferral is requested in this case. Please note this does not affect any nvmem device not using layouts, because an early check against the "nvmem-layout" container presence will return NULL in this case. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 16044377a41d..a66c37a03a36 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -762,7 +762,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { struct device_node *layout_np, *np =3D nvmem->dev.of_node; - struct nvmem_layout *l, *layout =3D NULL; + struct nvmem_layout *l, *layout =3D ERR_PTR(-EPROBE_DEFER); =20 layout_np =3D of_get_child_by_name(np, "nvmem-layout"); if (!layout_np) @@ -944,6 +944,13 @@ struct nvmem_device *nvmem_register(const struct nvmem= _config *config) * pointer will be NULL and nvmem_layout_put() will be a noop. */ nvmem->layout =3D config->layout ?: nvmem_layout_get(nvmem); + if (IS_ERR(nvmem->layout)) { + rval =3D PTR_ERR(nvmem->layout); + nvmem->layout =3D NULL; + + if (rval =3D=3D -EPROBE_DEFER) + goto err_teardown_compat; + } =20 if (config->cells) { rval =3D nvmem_add_cells(nvmem, config->cells, config->ncells); @@ -976,6 +983,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_= config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); nvmem_layout_put(nvmem->layout); +err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: --=20 2.34.1 From nobody Tue Sep 9 21:36:13 2025 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 B5AF9C64ED6 for ; Wed, 1 Mar 2023 15:23:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbjCAPXM (ORCPT ); Wed, 1 Mar 2023 10:23:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbjCAPWv (ORCPT ); Wed, 1 Mar 2023 10:22:51 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D69457FB; Wed, 1 Mar 2023 07:22:49 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id CAE8D60006; Wed, 1 Mar 2023 15:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=veHqp22wWolx6RiZnbbvLOutWer672c27ajS/GJmogc=; b=QVakPxE5LSVc9MxAkGBRSgmdbC2BCKTsWJTp+wDGqvTdkral5N3TNtKgiCFRSWhXG5WMjo y5voAUtX7dUaNEoz4+v3cznCrhhQUHj8r+Ed+5ErLy9xmAp1vlWxuXEhg04OX5ugK0GPyL 93jz84NT+MnJKYx0T9USiBDJoi7S4iw6u7cmM6iPY92N3I/kvUAGX1Y26ffb3X/Qgvl4mk BL1KrYcQhG+YUtNzK0hnsspmRuDzPDGIoxqb3wLc4zluZpbfKsjgRE5xRJjgfI/8p+w8hj ulvz8jQkBfFn67nqFORPXj3LqTsHOh7WddcKfqG3YTc1At9Sa30cswQW36Anpw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 6/8] nvmem: core: Request layout modules loading Date: Wed, 1 Mar 2023 16:22:37 +0100 Message-Id: <20230301152239.531194-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When a storage device like an eeprom or an mtd device probes, it registers an nvmem device if the nvmem subsystem has been enabled (bool symbol). During nvmem registration, if the device is using layouts to expose dynamic nvmem cells, the core will first try to get a reference over the layout driver callbacks. In practice there is not relationship that can be described between the storage driver and the nvmem layout. So there is no way we can enforce both drivers will be built-in or both will be modules. If the storage device driver is built-in but the layout is built as a module, instead of badly failing with an endless probe deferral loop, lets just make a modprobe call in case the driver was made available in an initramfs with of_device_node_request_module(), and offer a fully functional system to the user. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index a66c37a03a36..8e07b9df3221 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include =20 struct nvmem_device { @@ -768,6 +769,13 @@ static struct nvmem_layout *nvmem_layout_get(struct nv= mem_device *nvmem) if (!layout_np) return NULL; =20 + /* + * In case the nvmem device was built-in while the layout was built as a + * module, we shall manually request the layout driver loading otherwise + * we'll never have any match. + */ + of_device_node_request_module(layout_np); + spin_lock(&nvmem_layout_lock); =20 list_for_each_entry(l, &nvmem_layouts, node) { --=20 2.34.1 From nobody Tue Sep 9 21:36:13 2025 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 74EC6C64ED6 for ; Wed, 1 Mar 2023 15:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbjCAPXW (ORCPT ); Wed, 1 Mar 2023 10:23:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230312AbjCAPWz (ORCPT ); Wed, 1 Mar 2023 10:22:55 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D4810DE; Wed, 1 Mar 2023 07:22:51 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id EE1226000F; Wed, 1 Mar 2023 15:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X48eOuQR9g5TMfWe2rTj2NLQ7Kg+37T7XdPWVVAdg/k=; b=YvX0uQbYrMLltUcObHa7M12j5xm3cWqbzZKlrX3RdCRhiXDscazjQPndiZTGwwtj2HcxgN b6n+ufqWUB2cDnewB0mCllYIBgQ+6/Q4/h3HFl0SLwtDT9Cf164VTEucnEP4dd7exyrS0P fdbA67QELtFZc0Gyorwu42Y1sc0UKehjAV3ET7mpmZSzyEYcQl+zH6biyPPJvnCRTxgZqx RVmXriiXlUYJHp8ejHFh631aSjV2DJ/MycrkvC+/3mSMbfqp0UBPKuL7z2ProgjOLUBNEM FMDVe4+404vvh5SE2TKmSzZqs0+oQeiQ9lrmcEpENBDmYfQoihfReuelBdKIKg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 7/8] nvmem: layouts: sl28vpd: Convert layout driver into a module Date: Wed, 1 Mar 2023 16:22:38 +0100 Message-Id: <20230301152239.531194-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The nvmem core has already been converted to accept layout drivers compiled as modules. So in order to make this change effective we need to convert this driver so it can also be compiled as a module. We then need to expose the match table, provide MODULE_* macros, use module_init/exit() instead of the early subsys_initcall() and of course update the Kconfig symbol type to tristate. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/layouts/Kconfig | 2 +- drivers/nvmem/layouts/sl28vpd.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 9ad50474cb77..3f2d73282242 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -3,7 +3,7 @@ menu "Layout Types" =20 config NVMEM_LAYOUT_SL28_VPD - bool "Kontron sl28 VPD layout support" + tristate "Kontron sl28 VPD layout support" select CRC8 help Say Y here if you want to support the VPD layout of the Kontron diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vp= d.c index a36800f201a3..9370e41bad73 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -139,6 +139,7 @@ static const struct of_device_id sl28vpd_of_match_table= [] =3D { { .compatible =3D "kontron,sl28-vpd" }, {}, }; +MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); =20 struct nvmem_layout sl28vpd_layout =3D { .name =3D "sl28-vpd", @@ -150,4 +151,15 @@ static int __init sl28vpd_init(void) { return nvmem_layout_register(&sl28vpd_layout); } -subsys_initcall(sl28vpd_init); + +static void __exit sl28vpd_exit(void) +{ + nvmem_layout_unregister(&sl28vpd_layout); +} + +module_init(sl28vpd_init); +module_exit(sl28vpd_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Michael Walle "); +MODULE_DESCRIPTION("NVMEM layout driver for the VPD of Kontron sl28 boards= "); --=20 2.34.1 From nobody Tue Sep 9 21:36:13 2025 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 770F8C6FA9D for ; Wed, 1 Mar 2023 15:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbjCAPXZ (ORCPT ); Wed, 1 Mar 2023 10:23:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbjCAPW4 (ORCPT ); Wed, 1 Mar 2023 10:22:56 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CE761BA; Wed, 1 Mar 2023 07:22:52 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 3F1476000E; Wed, 1 Mar 2023 15:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q/yvRwDf0AdtbTrlrjDEi4BXF/Fzx1LyWUDN6tw49lM=; b=QaO/w24JvA08uvMecfKs3r8CgraP6VjdyZkEd/5pug68+pTJmHBixd1HJCmMo85/zrv3bn 56M8cs3BeKlGKeLmp1uYGwwGSEDlr8IoNrVry0MpPTXW0lUNAm7pF0wEUrO/l8mbnDPhG9 S5lj3Q4dae8TjES7TMFm1P9IPjQIBqwJxo7jWBbL8sI6PAP8LUgd0oJ0fN3gIzLRORP5Ts JwITliC2/ZSI0S3UwCttilFc3fzJKMQiaAX3wu/IuvhiJAuAh/2nf3LkY70bgFh7OE9sHA wISD71WHqi/EZyx+EMDKv6oKIUlu8lAfukcjNFr7n+/NL+EAbslHgeNSnjjT1Q== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 8/8] nvmem: layouts: onie-tlv: Convert layout driver into a module Date: Wed, 1 Mar 2023 16:22:39 +0100 Message-Id: <20230301152239.531194-9-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The nvmem core has already been converted to accept layout drivers compiled as modules. So in order to make this change effective we need to convert this driver so it can also be compiled as a module. We then need to expose the match table, provide MODULE_* macros, use module_init/exit() instead of the early subsys_initcall() and of course update the Kconfig symbol type to tristate. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/layouts/Kconfig | 2 +- drivers/nvmem/layouts/onie-tlv.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 3f2d73282242..7ff1ee1c1f05 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -12,7 +12,7 @@ config NVMEM_LAYOUT_SL28_VPD If unsure, say N. =20 config NVMEM_LAYOUT_ONIE_TLV - bool "ONIE tlv support" + tristate "ONIE tlv support" select CRC32 help Say Y here if you want to support the Open Compute Project ONIE diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-= tlv.c index 767f39fff717..d45b7301a69d 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -230,6 +230,7 @@ static const struct of_device_id onie_tlv_of_match_tabl= e[] =3D { { .compatible =3D "onie,tlv-layout", }, {}, }; +MODULE_DEVICE_TABLE(of, onie_tlv_of_match_table); =20 static struct nvmem_layout onie_tlv_layout =3D { .name =3D "ONIE tlv layout", @@ -241,4 +242,16 @@ static int __init onie_tlv_init(void) { return nvmem_layout_register(&onie_tlv_layout); } -subsys_initcall(onie_tlv_init); + +static void __exit onie_tlv_exit(void) +{ + nvmem_layout_unregister(&onie_tlv_layout); +} + +module_init(onie_tlv_init); +module_exit(onie_tlv_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Miquel Raynal "); +MODULE_DESCRIPTION("NVMEM layout driver for Onie TLV table parsing"); +MODULE_ALIAS("NVMEM layout driver for Onie TLV table parsing"); --=20 2.34.1