From patchwork Tue Aug 8 06:29:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 132763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2332638vqr; Tue, 8 Aug 2023 12:02:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgJuhlJDpGQMaa3M9+D71gqYOXdbMyYPwhh4z8Mx/mx/CGOc38ycRtiBPPxMDtbXITqdQ1 X-Received: by 2002:a5d:684d:0:b0:317:6513:da83 with SMTP id o13-20020a5d684d000000b003176513da83mr262031wrw.43.1691521339785; Tue, 08 Aug 2023 12:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691521339; cv=none; d=google.com; s=arc-20160816; b=vM/IsDh8f/WMDFW2S+5gR1mizwV49beAgvONnwEO5Q6sDqlzBKuP6jVQ1RKdyH97g/ phW5icRW+NuVCyY3EudVOmdk8DeuVLh2GKf2+XKC8HZ0VZGGBUM2m9vDPU8sLvWxTWaw 86Sf+7XdZtq5PEiLwPbCtIZt+7Z0tGDER/d67fRK4bMoyeVYE5Kxb5i9LPsoL0kZOJ8J ciRPI841wsOqaRYtnctSP6SvNuAYWc1X77Qd49+jr7QAuLZ2PGAnavRiAlL4qPP21ZuK vroEw8evdWUiBlQE+9wac8JESlrjtEslfvDZ15Vjvx13mCuhYsSCBcXR2VumrqFoiiBR +MaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=un3Uwaotmlox+IhpuLnflkjcgnz89/YG1Do8CcofnC8=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=deFHTfKtsiK3fIUTO5dxK20yHHqrhqSjB5+h9NbX9KJBqr/dTUJwsBO5yebPElvhx9 ab5W4GwfgQc9pqzbsMw7MmCy/TyHW57iPDQ1jvCJ+oHrKAZRwHXq2B0QQGrGJGQ8gS7j ukXaN8LMcJs3m3ZUmx9vddG1UrEi5Py+HDwBSnvp3xyKuP3HTNKD1eMfRnBnldPdzDvq gh5jj+bBMoCGxb1xNiL+oHADkrgQ7Maau7u4E3wdC1zirSmsrOti0N/1eQg7nXrRtAbq dytE1EiOEaFNwa84erZGhsCqCEDH88I8G/9VfrX9+w+IGB7LpF3Ehryv/ABToVYt54qu u/4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=m09o8WMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r25-20020aa7c159000000b0051e16fd4d9asi7525619edp.223.2023.08.08.12.01.55; Tue, 08 Aug 2023 12:02:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=m09o8WMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234725AbjHHRdS (ORCPT + 99 others); Tue, 8 Aug 2023 13:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234756AbjHHRck (ORCPT ); Tue, 8 Aug 2023 13:32:40 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 343D6F980 for ; Tue, 8 Aug 2023 09:14:10 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::221]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 53A85D2E91 for ; Tue, 8 Aug 2023 06:29:41 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8C7E8240002; Tue, 8 Aug 2023 06:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476176; 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=un3Uwaotmlox+IhpuLnflkjcgnz89/YG1Do8CcofnC8=; b=m09o8WMveylXIA6+Wxh05/Wjd4mUGCqxw+Q6xeYqPZYiU3wK95n/gIcX20uwb8X9VB+Z3W JcvC8NIkpn4ka2KXwDwxSs14CzsLkexWtSHmDIGcmq+DKqEj17TtpnDv/FIAFGu52e3c1S efIYy+fPq4Swu5/ETkwBqP4O8+W1Q8KMUzQJn6qjZnCKbae8FzRfVfIfLtji1sx+uU0S5E bPQa80hjjd2hI5OZeITss+kviY7Q9O9BfHRAQKNG5CiRFh3JpZQg4DlY3vJhLXKTlEQNCJ c1b4CBWCLF02QxsC8xWdZAntPnM0EUZr9wa+JPTUqW+tcA4wRl0H7TWoqPfI8Q== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v9 1/7] nvmem: core: Create all cells before adding the nvmem device Date: Tue, 8 Aug 2023 08:29:26 +0200 Message-Id: <20230808062932.150588-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773683299655425408 X-GMAIL-MSGID: 1773688680145057343 Let's pack all the cells creation in one place, so they are all created before we add the nvmem device. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 3f8c7718412b..48659106a1e2 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -998,12 +998,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); - - rval = device_add(&nvmem->dev); - if (rval) - goto err_remove_cells; - rval = nvmem_add_cells_from_fixed_layout(nvmem); if (rval) goto err_remove_cells; @@ -1012,6 +1006,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; + dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); + + rval = device_add(&nvmem->dev); + if (rval) + goto err_remove_cells; + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; From patchwork Tue Aug 8 06:29:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 132709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2325320vqr; Tue, 8 Aug 2023 11:48:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExvued2Yq/ps9k+9Ujp20tZl6a5UG/7D/2CCA/2ssTTa0HKqk86qTAPyC2Pfc1HsPsyWNl X-Received: by 2002:a17:903:1104:b0:1bc:45a8:c69a with SMTP id n4-20020a170903110400b001bc45a8c69amr545059plh.21.1691520502261; Tue, 08 Aug 2023 11:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691520502; cv=none; d=google.com; s=arc-20160816; b=GUcZnq1iICP2HW9N/1TdYw8B7mQc9wp5Ny8cZsYkEMB2PqJNBc4Q+tG+oGm0rdU9ev xncnABbjKagslnbEiKB9Eqd+cOAcDRas+nrOwwRw3/zSvYbXswsneusPDrMNyNvFksPF jSvWHDM51QfAbQ9QmV1JmXyKcQe3Rops9dJapNDcl5Ef0fz8YNnbRLUpW2k6EaEmdXEX T+EvLN5laGbjUBLBtM+U3ClA2G+FWDqkcFHNUt8UwNTpfZGoLDwJqT8YdFpmf/BgZ/rU N1/EuRsP/lGkPXtc8lySC6SWc7HkM3bwui45G1OvUjtejqSFmowxWo2iavVJwkSzzDda 5Ngw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bS+vOtPyOkEkdV/nhm5MLbH36mndj+2cFLrBIoA8aFE=; fh=f7aD74tELEZtFO9O5agOhsaIYt+Ay32d6f6zjupLJ4g=; b=k55uZHfiXRpF27jXQb6vGfNuAVB3+v9hTegBtF+P78Ah3WqaJ/iKcNoEG70+f62VB/ HmQRr5FeaXox+Cj73cs4Tg7byB7z8nFMPEF+EYQgh76ZulpOkSDdAxuXVk8gIHEdeDSd RgvbqaXZHaEBdB7bJlU8g08S7GP3SyUlA2IZIKAacGr1ZkJ2oKmF3eyLbSZ9b3THzlPK wB26x7VuN+OwoFXVMNnlL4DMLcY58M8ZCVLMHaehfIdrEUV+D5sbEe/icFQGnGU3WlUA 8qRw+C3fc08hXs/eF8Ztu9TnzHgO5Nt55DGzYFLHd+v1srpa7hYY1I5pB4DASx852h2B hUoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=hmZdhcJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w3-20020a170902e88300b001b87b716f87si1606758plg.329.2023.08.08.11.48.09; Tue, 08 Aug 2023 11:48:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=hmZdhcJM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232646AbjHHRma (ORCPT + 99 others); Tue, 8 Aug 2023 13:42:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234036AbjHHRls (ORCPT ); Tue, 8 Aug 2023 13:41:48 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D62F238FE for ; Tue, 8 Aug 2023 09:18:29 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [IPv6:2001:4b98:dc4:8::221]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 6409AD2EC1 for ; Tue, 8 Aug 2023 06:29:55 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id CAD39240007; Tue, 8 Aug 2023 06:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476178; 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=bS+vOtPyOkEkdV/nhm5MLbH36mndj+2cFLrBIoA8aFE=; b=hmZdhcJMLGN3+DbMpvMXzXuhrzlVj07IbxZyeePTN2JyLD/a4NiUtN4gIhsGaxBb2XmDnX lDvW/O/OeoxxLFtu2Ox/AtXUf8XDhli58FiYcE9/ABE6BSDCTuyYUVsA9HAGkd3pXqZlda jV5gb4hz3TBCnvpWHyErNG19MG20VyuvdHWEWfj4VKquO10teScjrO00EADRIUS0GAQ/Gc +xEOe/SdIFXUJRHoKtwZvauUmU0RQlzxRYZxg4Vzg1Npwzma1Nq6rnJy4LFreEpdjiCCVH RFc3JzffgR4WyC5JzOFJWXeIyGAwHqsIfwXo9xw5iyRm5unlW59VQRtlL0otFw== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal , kernel test robot , Dan Carpenter Subject: [PATCH v9 2/7] nvmem: core: Return NULL when no nvmem layout is found Date: Tue, 8 Aug 2023 08:29:27 +0200 Message-Id: <20230808062932.150588-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773684451226623061 X-GMAIL-MSGID: 1773687801925703681 Currently, of_nvmem_layout_get_container() returns NULL on error, or an error pointer if either CONFIG_NVMEM or CONFIG_OF is turned off. We should likely avoid this kind of mix for two reasons: to clarify the intend and anyway fix the !CONFIG_OF which will likely always if we use this helper somewhere else. Let's just return NULL when no layout is found, we don't need an error value here. Link: https://staticthinking.wordpress.com/2022/08/01/mixing-error-pointers-and-null/ Fixes: 266570f496b9 ("nvmem: core: introduce NVMEM layouts") Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202308030002.DnSFOrMB-lkp@intel.com/ Signed-off-by: Miquel Raynal --- Backports to stable kernels is likely not needed as I believe the error pointer will be discarded "magically" by the of/ code. --- include/linux/nvmem-consumer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index fa030d93b768..27373024856d 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -256,7 +256,7 @@ static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, static inline struct device_node * of_nvmem_layout_get_container(struct nvmem_device *nvmem) { - return ERR_PTR(-EOPNOTSUPP); + return NULL; } #endif /* CONFIG_NVMEM && CONFIG_OF */ From patchwork Tue Aug 8 06:29:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 132921 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2433411vqr; Tue, 8 Aug 2023 15:32:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQ9fWLSCGfw9x1qutKZNwc8pc4fB/ImIUtAdbV6xCPOy6CKFwu7o+E0gJbRqY4e8wLXSuw X-Received: by 2002:a05:6300:808c:b0:138:2fb8:6b42 with SMTP id ap12-20020a056300808c00b001382fb86b42mr788654pzc.14.1691533974701; Tue, 08 Aug 2023 15:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691533974; cv=none; d=google.com; s=arc-20160816; b=ert3tC5eX9EjZ9fPAFnX9UOuGJTApiKJpDWjNqaTgMYbiEoNsWlciDr8FYUeZK7kNg vQdULic/TRJxSv5r0v+If4BGY04nCMi4pp2zqP36FfZ39FlD9wsPst/6USokRQeq7Mkg znx/KqkccfLkWhZr3U7ufQp4BiypX7phvQF6LahWA8+HihZtEbzIgQp9QEpuI0FDvpZZ o9je4CQBayJ1swhc53NMpmwLTRnIICBc5VeXWUQVTSUf4uifzhmqt1lT0XBHF62V/fKr SFNYSp7vNXqXaIuzclDutt1VOUuyDqqDp5nmuQDA70eyY4q/B3bFV8CUuNw6NczyA+od 57xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X3Zr5zi6oiutEUY5SskrgH9VYy6BX6UnhftLaueXlCU=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=wyx70EXqM7PK2bHMH+I5IbKOiWgwxxqFVsQYfYKHutOObGMsoIlSRckuX70I6YRKN5 7OIjt97az77jqQK0xIXQ8vTWiRbEeev8Paz3gHzzeLOhOzilnuYqL15bnUtDd80nkAlf U1mKUKg6aFtzhjA6XnKQxkBLlyUrLy/mWqv5bej1TQNLN5P7EYCMnJhhmKx4uCCzA2X5 2mmVSrdZ9fibY0SFni/FzJYPCLYDIVLD2Vsk8rUSkhNPh1rr9wJ4Fm8RPLNgUpEzNCZ4 s0xy7etCkzK9yf0TQd45FS3RGq2f8yAfTDTI/9KLWbHLeghB2MRJY/YaifG3fdUlLMRh 6O3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nfxXacI4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fb26-20020a056a002d9a00b00687505e2bb8si8145511pfb.24.2023.08.08.15.32.41; Tue, 08 Aug 2023 15:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nfxXacI4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbjHHTv1 (ORCPT + 99 others); Tue, 8 Aug 2023 15:51:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233209AbjHHTvE (ORCPT ); Tue, 8 Aug 2023 15:51:04 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69ABC550E3 for ; Tue, 8 Aug 2023 09:57:02 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 7F47ED2EAB for ; Tue, 8 Aug 2023 06:29:44 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 4DAC0240009; Tue, 8 Aug 2023 06:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476179; 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=X3Zr5zi6oiutEUY5SskrgH9VYy6BX6UnhftLaueXlCU=; b=nfxXacI46SMugrnbW8CpNixY6lUc08T2a/xyLcq9Vbw+tn1Imt9HYCNQFEQH2GV2DLKAjo cpfn/Ytaf3rWv0B9CCRTjwtiNscMlZkMztS7liNYaXudaLaiMbXul36dryAWNh56IIkbYF et65n1hyiqIq0hnUVPp2RYYbPoN4F55hO4t3+gRHjzmL3ZrLMo9P42BLsXHAKnISBbKDeK q5/Eh1jKAVJowXOedYJMuyfuqEfcre+PHdzYJD7+PFFnDEdq2bsvJzo/AmlP+Jg+t5QxlC +bjNRQp0wKEGLJhylvVpzCDK3aqz+p//qXYWZ/7PdrGAqgR3wk7QX6i8QEskkw== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v9 3/7] nvmem: core: Do not open-code existing functions Date: Tue, 8 Aug 2023 08:29:28 +0200 Message-Id: <20230808062932.150588-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773687266362202844 X-GMAIL-MSGID: 1773701928905902058 Use of_nvmem_layout_get_container() instead of hardcoding it. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 48659106a1e2..257328887263 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -786,10 +786,10 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { - struct device_node *layout_np, *np = nvmem->dev.of_node; + struct device_node *layout_np; struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); - layout_np = of_get_child_by_name(np, "nvmem-layout"); + layout_np = of_nvmem_layout_get_container(nvmem); if (!layout_np) return NULL; From patchwork Tue Aug 8 06:29:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 132942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2438345vqr; Tue, 8 Aug 2023 15:45:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsCe9wl8eD9mFaKx72GuBBR0YvidK31WKdPip9c+J4kbe7QidJHuxn7PEOceqsAlknlbmq X-Received: by 2002:a05:6808:d0:b0:3a7:2456:6af6 with SMTP id t16-20020a05680800d000b003a724566af6mr1096888oic.31.1691534758081; Tue, 08 Aug 2023 15:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691534758; cv=none; d=google.com; s=arc-20160816; b=ABwMcL8xMIUIonc1buQSGzzHBHxdtzFWIEtif+e61wqGPem8GxAH2nlbXj5PpI2LmC Xo0KrJK60BVj37MXj/1uOhPbtBiGRXZWPYfq5Hag5Dbq3GzipqLC67Gf6+XqF1HhhwpY DYqfDlpymJObUrPyZaLqC+FUzbyWDHDAKWsW2quctivs9X2TJGpu2BsvEJJv/P+hPlhm xDTxyJNFVctJ8LN33OhvUj1QanFdP0hyYN8+t7RdMY0BJmf79LWjtyEdEqJZTWeeEG0n DMELOzoCEoF2JaUzNUoJ58M8gnzmAZxEsZp+1RW1ANbZfazrOX6n+SxbStBvbbScemlK nN6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4uLCgToS16/0CGtApzHhwLVg0LDST2ybBj3RK0mHpVg=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=fMPtCsWujisUroPXp3eyPPhTTgQY4tmTtRv6pLzu4hceNusfU+wi9CoBF1fNw/HtdG MKYsux6l2X+YOzxfA7N3RsvUmlYpnj9l4E7RLrewg19ydvXy7EWetjVECFEvyIyEnZF6 4UoLCNgrfey2q7wX+WGxYoZIzlX695Ml9l/PNwJka4MCSnfi40QNO6KuAZYVskoi71cF L3RhrtCXSFiB/wSh8WMF7sIODNSFlcZPYB3GaYsUZGgcezgXlFcS88QmRcMVNBDVAO+A rZ3jpdAgBKsm8urJiUWaulVaTnVeiVk3X95ZSRviP2BKNvwGBqvBULhtStmXC/g1QFqM Pizw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=a9ZoX82P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b16-20020a17090ae39000b002680e08a877si84370pjz.186.2023.08.08.15.45.45; Tue, 08 Aug 2023 15:45:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=a9ZoX82P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235251AbjHHSIc (ORCPT + 99 others); Tue, 8 Aug 2023 14:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235313AbjHHSIK (ORCPT ); Tue, 8 Aug 2023 14:08:10 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BFE663D56 for ; Tue, 8 Aug 2023 10:09:22 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 93E0AD2E95 for ; Tue, 8 Aug 2023 06:29:42 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 639C324000B; Tue, 8 Aug 2023 06:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476180; 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=4uLCgToS16/0CGtApzHhwLVg0LDST2ybBj3RK0mHpVg=; b=a9ZoX82PEUVHuMLJ0ldJ9i/mxqfnVpm1OrRlYhfL5hdvTMGCNJ3vlzlbTvfBB+Z0BRxNoN ZjRs6//ZPBhxsmuTU5eDY/PfMQxnOgFBZ/E9S0MK0tRPIJWRVDYNBnBICVwNivvdqml5XH 4WU216O0Ih81RT1CePWzoQl3a9OEvLnPwbvCJCCfhvlIvUSwHtqiF9VMRSOmT1qs2T8NYT YyFu8UJGL7GPelBSOvrCeASSbS9r6EtXx0AB8D68ryeqPE0lidf6diLIY8pn3NdJDNjqq9 lOkQag55axHHLt+Y0Eqo7nk/nqNqil6LUQ6Kfv/N2F7iHTW9ubz2+8D6ECxKZg== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v9 4/7] nvmem: core: Notify when a new layout is registered Date: Tue, 8 Aug 2023 08:29:29 +0200 Message-Id: <20230808062932.150588-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773702750537585240 X-GMAIL-MSGID: 1773702750537585240 Tell listeners a new layout was introduced and is now available. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-consumer.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 257328887263..4fb6d4d7fe40 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -772,12 +772,16 @@ int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner) list_add(&layout->node, &nvmem_layouts); spin_unlock(&nvmem_layout_lock); + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_ADD, layout); + return 0; } EXPORT_SYMBOL_GPL(__nvmem_layout_register); void nvmem_layout_unregister(struct nvmem_layout *layout) { + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_LAYOUT_REMOVE, layout); + spin_lock(&nvmem_layout_lock); list_del(&layout->node); spin_unlock(&nvmem_layout_lock); diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 27373024856d..4523e4e83319 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -43,6 +43,8 @@ enum { NVMEM_REMOVE, NVMEM_CELL_ADD, NVMEM_CELL_REMOVE, + NVMEM_LAYOUT_ADD, + NVMEM_LAYOUT_REMOVE, }; #if IS_ENABLED(CONFIG_NVMEM) From patchwork Tue Aug 8 06:29:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 132847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2375760vqr; Tue, 8 Aug 2023 13:25:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJSzj5Vvo98Hr5VXUMSc7xYx3e1KU1pOioTEnHOYX+OGz1p8JPevDN9h4S1hCdWIqi41UW X-Received: by 2002:a9d:7510:0:b0:6b0:c67c:96f3 with SMTP id r16-20020a9d7510000000b006b0c67c96f3mr730603otk.18.1691526351654; Tue, 08 Aug 2023 13:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691526351; cv=none; d=google.com; s=arc-20160816; b=NtSD9XgvLMI8vEtWlyGRuWzYTUXW2xzD+GKCT2nWUR7dnevyjoQT0T/n3zU/EdrrZt EXMaFZI9K6D99aC1GCfeO61Ww8UKBGC0joCSokTt4oPJYbBls/K7mhUgnnv72JXB0HgN fToUCTdl+GLY7e3cVTYjCyMDfeTvHzXmsGgNOR0n4QHYa34nUKhZLJ32TNVKk1MM4TRk dEhB0khJNzq/9xUncmIWv3STj/cvT2jLKE9ASewt9y1LU7ptRmQnmf79OsO7wrePjYk0 ZdJLyZ0MIixGi+IkAdOJ5LZ7VeX/ET0UnoBQu8YW4UgHli///uufZvEUSOBObKKXqoiq ZlQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mzsUmbilO/YOtK0+lVad8Kb036Mk6Wsg3mMsxO0/+g0=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=RQ5TxuxqhwTr3gjGAApuOTaeR4e1LqN8BgR0dfnAVvhkqKpG22jdy/5q06m+g1Xi0P zNh+V0HNvEOUGyEQW0LGOlUYbsoiDjDz9w8o5bsrOmcHu2zijZSV+p3wijOHh5s3tRsP WkfAwelNR3NI+v5F+v6t7Lx+7qxCi/jxr+/azzH8KNX5Pm23iGlINVIeQwz15SfML3ox YnhlFC6nRBu+QEOeDzn0u9WXqMRiHOpikfuwICjrf57QC9N5NmUEkAelKtRA4LbEGMP4 2boMWixFvYnWiBse5am0AOpNHNHyo9PBECAjtjNNJVxse5TR9DSUHmHSlI8fIMzfnXOF PQNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=niTd2B4T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a634f07000000b0055c07307e5bsi7806338pgb.64.2023.08.08.13.25.37; Tue, 08 Aug 2023 13:25:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=niTd2B4T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234413AbjHHRUO (ORCPT + 99 others); Tue, 8 Aug 2023 13:20:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbjHHRTv (ORCPT ); Tue, 8 Aug 2023 13:19:51 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0198275876 for ; Tue, 8 Aug 2023 09:07:57 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 7F02BD2EA7 for ; Tue, 8 Aug 2023 06:29:44 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8D9D5240005; Tue, 8 Aug 2023 06:29:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476181; 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=mzsUmbilO/YOtK0+lVad8Kb036Mk6Wsg3mMsxO0/+g0=; b=niTd2B4Tmjm7QTDBUFTRieaRxXATJSWIJjNyJVjwFW58HJt0JW7Em0eCn334OA2jyG/X+r 9/bw8GNO/Cqq1K8MqeHFdvOHNQtgICTQ+PXyIidtb7K6fWHC31/9Ngfey4fKbh/QfaphQm b6QoSZ/Euo9vnap2QPnT9oCNbQlQa0NgwlK8pt6NVlSEAUJOpJ9m8PSGtbxWmdEiYgvWs4 NJyf1T1gB1NRwY4tB0M5wniPF5hCE7CQQStwvZWIoLu6/FIWzE2KzNEabsHnIMyy10xeBT Lzk4GFteQBXdo6rGmb3zcJtmFxeV6Lc12hm7byWn2BJhwtiHDiiRjcJqgEopEg== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v9 5/7] nvmem: core: Rework layouts to become platform devices Date: Tue, 8 Aug 2023 08:29:30 +0200 Message-Id: <20230808062932.150588-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773693935829927660 X-GMAIL-MSGID: 1773693935829927660 Current layout support was initially written without modules support in mind. When the requirement for module support rose, the existing base was improved to adopt modularization support, but kind of a design flaw was introduced. With the existing implementation, when a storage device registers into NVMEM, the core tries to hook a layout (if any) and populates its cells immediately. This means, if the hardware description expects a layout to be hooked up, but no driver was provided for that, the storage medium will fail to probe and try later from scratch. Technically, the layouts are more like a "plus" and, even we consider that the hardware description shall be correct, we could still probe the storage device (especially if it contains the rootfs). One way to overcome this situation is to consider the layouts as devices, and leverage the existing notifier mechanism. When a new NVMEM device is registered, we can: - populate its nvmem-layout child, if any - try to modprobe the relevant driver, if relevant - try to hook the NVMEM device with a layout in the notifier And when a new layout is registered: - try to hook all the existing NVMEM devices which are not yet hooked to a layout with the new layout This way, there is no strong order to enforce, any NVMEM device creation or NVMEM layout driver insertion will be observed as a new event which may lead to the creation of additional cells, without disturbing the probes with costly (and sometimes endless) deferrals. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 139 ++++++++++++++++++++++++------- drivers/nvmem/layouts/onie-tlv.c | 39 +++++++-- drivers/nvmem/layouts/sl28vpd.c | 39 +++++++-- include/linux/nvmem-provider.h | 11 +-- 4 files changed, 179 insertions(+), 49 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 4fb6d4d7fe40..32d9973df90b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -23,6 +23,7 @@ struct nvmem_device { struct module *owner; struct device dev; + struct list_head node; int stride; int word_size; int id; @@ -76,6 +77,7 @@ static LIST_HEAD(nvmem_cell_tables); static DEFINE_MUTEX(nvmem_lookup_mutex); static LIST_HEAD(nvmem_lookup_list); +struct notifier_block nvmem_nb; static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); static DEFINE_SPINLOCK(nvmem_layout_lock); @@ -791,23 +793,16 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { struct device_node *layout_np; - struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); + struct nvmem_layout *l, *layout = NULL; layout_np = of_nvmem_layout_get_container(nvmem); if (!layout_np) return NULL; - /* - * 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_request_module(layout_np); - spin_lock(&nvmem_layout_lock); list_for_each_entry(l, &nvmem_layouts, node) { - if (of_match_node(l->of_match_table, layout_np)) { + if (of_match_node(l->dev->driver->of_match_table, layout_np)) { if (try_module_get(l->owner)) layout = l; @@ -864,7 +859,7 @@ const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, const struct of_device_id *match; layout_np = of_nvmem_layout_get_container(nvmem); - match = of_match_node(layout->of_match_table, layout_np); + match = of_match_node(layout->dev->driver->of_match_table, layout_np); return match ? match->data : NULL; } @@ -883,6 +878,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data); struct nvmem_device *nvmem_register(const struct nvmem_config *config) { struct nvmem_device *nvmem; + struct device_node *layout_np; int rval; if (!config->dev) @@ -975,19 +971,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) goto err_put_device; } - /* - * If the driver supplied a layout by config->layout, the module - * pointer will be NULL and nvmem_layout_put() will be a noop. - */ - nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); - if (IS_ERR(nvmem->layout)) { - rval = PTR_ERR(nvmem->layout); - nvmem->layout = NULL; - - if (rval == -EPROBE_DEFER) - goto err_teardown_compat; - } - if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) @@ -1006,24 +989,27 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; - rval = nvmem_add_cells_from_layout(nvmem); - if (rval) - goto err_remove_cells; - dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); rval = device_add(&nvmem->dev); if (rval) goto err_remove_cells; + /* Populate layouts as devices */ + layout_np = of_nvmem_layout_get_container(nvmem); + if (layout_np) { + rval = of_platform_populate(nvmem->dev.of_node, NULL, NULL, NULL); + if (rval) + goto err_remove_cells; + of_node_put(layout_np); + } + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; 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: @@ -2125,13 +2111,106 @@ const char *nvmem_dev_name(struct nvmem_device *nvmem) } EXPORT_SYMBOL_GPL(nvmem_dev_name); +static void nvmem_try_loading_layout_driver(struct nvmem_device *nvmem) +{ + struct device_node *layout_np; + + layout_np = of_nvmem_layout_get_container(nvmem); + if (layout_np) { + of_request_module(layout_np); + of_node_put(layout_np); + } +} + +static int nvmem_match_available_layout(struct nvmem_device *nvmem) +{ + int ret; + + if (nvmem->layout) + return 0; + + nvmem->layout = nvmem_layout_get(nvmem); + if (!nvmem->layout) + return 0; + + ret = nvmem_add_cells_from_layout(nvmem); + if (ret) { + nvmem_layout_put(nvmem->layout); + nvmem->layout = NULL; + return ret; + } + + return 0; +} + +static int nvmem_dev_match_available_layout(struct device *dev, void *data) +{ + struct nvmem_device *nvmem = to_nvmem_device(dev); + + return nvmem_match_available_layout(nvmem); +} + +static int nvmem_for_each_dev(int (*fn)(struct device *dev, void *data)) +{ + return bus_for_each_dev(&nvmem_bus_type, NULL, NULL, fn); +} + +/* + * When an NVMEM device is registered, try to match against a layout and + * populate the cells. When an NVMEM layout is probed, ensure all NVMEM devices + * which could use it properly expose their cells. + */ +static int nvmem_notifier_call(struct notifier_block *notifier, + unsigned long event_flags, void *context) +{ + struct nvmem_device *nvmem = NULL; + int ret; + + switch (event_flags) { + case NVMEM_ADD: + nvmem = context; + break; + case NVMEM_LAYOUT_ADD: + break; + default: + return NOTIFY_DONE; + } + + if (nvmem) { + /* + * In case the nvmem device was built-in while the layout was + * built as a module, manually request loading the layout driver. + */ + nvmem_try_loading_layout_driver(nvmem); + + /* Populate the cells of the new nvmem device from its layout, if any */ + ret = nvmem_match_available_layout(nvmem); + } else { + /* NVMEM devices might be "waiting" for this layout */ + ret = nvmem_for_each_dev(nvmem_dev_match_available_layout); + } + + if (ret) + return notifier_from_errno(ret); + + return NOTIFY_OK; +} + static int __init nvmem_init(void) { - return bus_register(&nvmem_bus_type); + int ret; + + ret = bus_register(&nvmem_bus_type); + if (ret) + return ret; + + nvmem_nb.notifier_call = &nvmem_notifier_call; + return nvmem_register_notifier(&nvmem_nb); } static void __exit nvmem_exit(void) { + nvmem_unregister_notifier(&nvmem_nb); bus_unregister(&nvmem_bus_type); } diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c index 59fc87ccfcff..3d54d3be2c93 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -13,6 +13,7 @@ #include #include #include +#include #define ONIE_TLV_MAX_LEN 2048 #define ONIE_TLV_CRC_FIELD_SZ 6 @@ -226,18 +227,46 @@ static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem, return 0; } +static int onie_tlv_probe(struct platform_device *pdev) +{ + struct nvmem_layout *layout; + + layout = devm_kzalloc(&pdev->dev, sizeof(*layout), GFP_KERNEL); + if (!layout) + return -ENOMEM; + + layout->add_cells = onie_tlv_parse_table; + layout->dev = &pdev->dev; + + platform_set_drvdata(pdev, layout); + + return nvmem_layout_register(layout); +} + +static int onie_tlv_remove(struct platform_device *pdev) +{ + struct nvmem_layout *layout = platform_get_drvdata(pdev); + + nvmem_layout_unregister(layout); + + return 0; +} + static const struct of_device_id onie_tlv_of_match_table[] = { { .compatible = "onie,tlv-layout", }, {}, }; MODULE_DEVICE_TABLE(of, onie_tlv_of_match_table); -static struct nvmem_layout onie_tlv_layout = { - .name = "ONIE tlv layout", - .of_match_table = onie_tlv_of_match_table, - .add_cells = onie_tlv_parse_table, +static struct platform_driver onie_tlv_layout = { + .driver = { + .name = "onie-tlv-layout", + .of_match_table = onie_tlv_of_match_table, + }, + .probe = onie_tlv_probe, + .remove = onie_tlv_remove, }; -module_nvmem_layout_driver(onie_tlv_layout); +module_platform_driver(onie_tlv_layout); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Miquel Raynal "); diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c index 05671371f631..ad0c39fc7943 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #define SL28VPD_MAGIC 'V' @@ -135,18 +136,46 @@ static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem, return 0; } +static int sl28vpd_probe(struct platform_device *pdev) +{ + struct nvmem_layout *layout; + + layout = devm_kzalloc(&pdev->dev, sizeof(*layout), GFP_KERNEL); + if (!layout) + return -ENOMEM; + + layout->add_cells = sl28vpd_add_cells; + layout->dev = &pdev->dev; + + platform_set_drvdata(pdev, layout); + + return nvmem_layout_register(layout); +} + +static int sl28vpd_remove(struct platform_device *pdev) +{ + struct nvmem_layout *layout = platform_get_drvdata(pdev); + + nvmem_layout_unregister(layout); + + return 0; +} + static const struct of_device_id sl28vpd_of_match_table[] = { { .compatible = "kontron,sl28-vpd" }, {}, }; MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); -static struct nvmem_layout sl28vpd_layout = { - .name = "sl28-vpd", - .of_match_table = sl28vpd_of_match_table, - .add_cells = sl28vpd_add_cells, +static struct platform_driver sl28vpd_layout = { + .driver = { + .name = "kontron-sl28vpd-layout", + .of_match_table = sl28vpd_of_match_table, + }, + .probe = sl28vpd_probe, + .remove = sl28vpd_remove, }; -module_nvmem_layout_driver(sl28vpd_layout); +module_platform_driver(sl28vpd_layout); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Michael Walle "); diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index dae26295e6be..c72064780b50 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -154,8 +154,7 @@ struct nvmem_cell_table { /** * struct nvmem_layout - NVMEM layout definitions * - * @name: Layout name. - * @of_match_table: Open firmware match table. + * @dev: Device-model layout device. * @add_cells: Will be called if a nvmem device is found which * has this layout. The function will add layout * specific cells with nvmem_add_one_cell(). @@ -170,8 +169,7 @@ struct nvmem_cell_table { * cells. */ struct nvmem_layout { - const char *name; - const struct of_device_id *of_match_table; + struct device *dev; int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, struct nvmem_layout *layout); void (*fixup_cell_info)(struct nvmem_device *nvmem, @@ -243,9 +241,4 @@ nvmem_layout_get_match_data(struct nvmem_device *nvmem, } #endif /* CONFIG_NVMEM */ - -#define module_nvmem_layout_driver(__layout_driver) \ - module_driver(__layout_driver, nvmem_layout_register, \ - nvmem_layout_unregister) - #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ From patchwork Tue Aug 8 06:29:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 132648 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2295534vqr; Tue, 8 Aug 2023 10:57:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEO3eE41gibRW9EJIP42vRJ8gBrUNZLOaycQ05N5LuOK0z6G0moWDANeT1h4yjbgyvJTXJx X-Received: by 2002:a05:6a20:970a:b0:135:1af6:9a01 with SMTP id hr10-20020a056a20970a00b001351af69a01mr250149pzc.8.1691517457953; Tue, 08 Aug 2023 10:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691517457; cv=none; d=google.com; s=arc-20160816; b=eHWrxkHOV2AlV48G69MM8v+KV6b84TQ4r1c8BLVrlTwfGxcMLVSHPpWtmHptrJuiY0 KTS/75M0ho5iUCLHb91fB6DH6AAe2HOCPNvj1PZgZ2+5BX0oqeKJeEWv1UALmHGU6FnE xLKMLzUGg9H69rILiFhlXV9qqud1KtoogvTakuFogr5s2khr8zUqXwr8Sr9p5S4D7S8N 1B1Gr+xhK3ghoqWQ2084edmeSv4ibilBS3kYdiMeZUDPw9rFP86XpLJq/uIBT76khtWm NbZ9BoFjmg7dJsTYWRBeJlZTHsUhb+zp87XJW5H7rFfjwrppo6QNyAWZh58pRxdGd3in ZgLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dfOp8t/SWXoAMbVxsmdWr6p/Yay0CylcPPBrARczmbM=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=dsX4RDz+08heNrPSyYmn6vcqJ/2pUWRGcSyu3a9vhnYW7kjZVVJbSkSDpptJndAuaG A0VD4lPltShri0t/+mlATJH5i89lsqF6Q8dzsozE2hpj5YZNB4RIU+Y+92OevleRoQgY OL3apUXi3oYToA9qxgsVFN3UdNRdHMbGaJIjxGAS7Kdqwvljl8DXASmm/o5BB2SRIYb8 wkQeE8PQv14Wzsww1vHCxBQyyhdhBDUKalj39v48XD+jKgG387Fpg3iX6Sk12Q9BRuX4 iaaqfwBfFbiLzbNoPUuul0Y+y9bDpIyaCZgGWLaGLVutLC4nuvIperCgNRFdgYxW71+f gCqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=aPlicZy0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a63c008000000b005642341d635si7227244pgg.373.2023.08.08.10.57.24; Tue, 08 Aug 2023 10:57:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=aPlicZy0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232569AbjHHRPt (ORCPT + 99 others); Tue, 8 Aug 2023 13:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234113AbjHHRPL (ORCPT ); Tue, 8 Aug 2023 13:15:11 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160AD6F480 for ; Tue, 8 Aug 2023 09:06:15 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow1.mail.gandi.net (Postfix) with ESMTP id CDEFAD2E96 for ; Tue, 8 Aug 2023 06:29:42 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id C88CE24000E; Tue, 8 Aug 2023 06:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476182; 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=dfOp8t/SWXoAMbVxsmdWr6p/Yay0CylcPPBrARczmbM=; b=aPlicZy0aPqt9XsWb2nXiOrAppv/JeO7nsjgYBSfEYe5L3RdHR7InI1x+hVetQWIy4RoaZ a2TbAmK8kWZszZdGQgPlblHYwmyI9y67Nrr64mnNC0ckatbaI9YIwwsY+HgKkH/6YKQdPx m9/rz+5DJM9wBkQ7C5/6uNhwBhYV6amMqKZtpH2SyfSc0Zck61wLBvlMGRCe8ULcnpvc/r 9hJGwuMmc7j+wopMKyU9thd5TouF1Xaai1RBnYF4bv5rcomTEEby8q85+TIai6Ll/zLMgk 87pKnEmmmBH2VvF+qRPTUPuFhZcTpqeWy7W7mczztu0FanxudL0fiDkh/abSyw== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v9 6/7] ABI: sysfs-nvmem-cells: Expose cells through sysfs Date: Tue, 8 Aug 2023 08:29:31 +0200 Message-Id: <20230808062932.150588-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773684610418072902 X-GMAIL-MSGID: 1773684610418072902 The binary content of nvmem devices is available to the user so in the easiest cases, finding the content of a cell is rather easy as it is just a matter of looking at a known and fixed offset. However, nvmem layouts have been recently introduced to cope with more advanced situations, where the offset and size of the cells is not known in advance or is dynamic. When using layouts, more advanced parsers are used by the kernel in order to give direct access to the content of each cell regardless of their position/size in the underlying device, but these information were not accessible to the user. By exposing the nvmem cells to the user through a dedicated cell/ folder containing one file per cell, we provide a straightforward access to useful user information without the need for re-writing a userland parser. Content of nvmem cells is usually: product names, manufacturing date, MAC addresses, etc, Signed-off-by: Miquel Raynal Reviewed-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-nvmem-cells | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-nvmem-cells diff --git a/Documentation/ABI/testing/sysfs-nvmem-cells b/Documentation/ABI/testing/sysfs-nvmem-cells new file mode 100644 index 000000000000..7af70adf3690 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-nvmem-cells @@ -0,0 +1,21 @@ +What: /sys/bus/nvmem/devices/.../cells/ +Date: May 2023 +KernelVersion: 6.5 +Contact: Miquel Raynal +Description: + The "cells" folder contains one file per cell exposed by the + NVMEM device. The name of the file is: @, with + being the cell name and its location in the NVMEM + device, in hexadecimal (without the '0x' prefix, to mimic device + tree node names). The length of the file is the size of the cell + (when known). The content of the file is the binary content of + the cell (may sometimes be ASCII, likely without trailing + character). + Note: This file is only present if CONFIG_NVMEM_SYSFS + is enabled. + + Example:: + + hexdump -C /sys/bus/nvmem/devices/1-00563/cells/product-name@d + 00000000 54 4e 34 38 4d 2d 50 2d 44 4e |TN48M-P-DN| + 0000000a From patchwork Tue Aug 8 06:29:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 132744 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2329898vqr; Tue, 8 Aug 2023 11:57:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEs9js/sFGREw8k1Mq0KehVopqJecc967bXnTV2kKv3J+VV2OEOYRWCbponEM8NqqKoDFqm X-Received: by 2002:a05:6870:5ba0:b0:1b3:f370:79c7 with SMTP id em32-20020a0568705ba000b001b3f37079c7mr510288oab.37.1691521072952; Tue, 08 Aug 2023 11:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691521072; cv=none; d=google.com; s=arc-20160816; b=p9E/o4KKQyqlTN6RVI6KWFvYy+qP44YVehsG6223XdDXOEJ8ZcpT1d9wwUNNUtN+y3 oUz7tlg788lPmPGs80aVF4+M9NF9Ed+j5DhlWdh6lip8lXFedfsccevV2DojyeX/7mU0 5oo3Fn4US7Sy9s0zJ16y3/DCJJiLCeqscngPYNYm7anBAmT88f4lRKzvZqwnv2253IgY Jrd7UgBniDNvMGfz7fR8HyyEA/+buRqI8SOmjk/PkjgkfdWa4cGnoXCc/SYIARcYDT4Q gaNjXko3uw0uY6/MI6Ymy7slR+lmK/Cr1JqgN6zkrm5hvQDECDc1uIgy3mIGOzi6I3kK PMqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0vlOW+m6/kgqn3cxpsCF/6Z4kqpXbg8aetH5L3Z+xlI=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=QSiHv8pzgTvM5XhWnPzbxZCrePNvccD7y/DIbfeQsUUnO4KjTNx6gufV5fT957p5lj hfkn65WqcbwpYNd+61gn4JhR8Kc0kVmRvFfjdeSIaGVpYjJ7e5QD3CcMgpDoa7hx0v8y K0bUc/6nuZ1NcbYeIIdX2VhUiAgd666fCHS0ERhuX9pys43ViQQECJka2ZNtWwODfYGQ pqXtgt9sRb9+4Wvnl99WdjOoBF8vSPhvp9TJPFNGkAiGTop6COOF5Uq3hCcyLOteM8kJ Fund9P4hobtM+6NMQ0y3doXDu26AAj7lWj+c2lqdJQ3da/TloCOYBSBB+MQOFNULzet9 SrgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=iGc2Ymhm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r185-20020a632bc2000000b0055c4c9cbfedsi7792769pgr.862.2023.08.08.11.57.39; Tue, 08 Aug 2023 11:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=iGc2Ymhm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234502AbjHHRXR (ORCPT + 99 others); Tue, 8 Aug 2023 13:23:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230417AbjHHRWp (ORCPT ); Tue, 8 Aug 2023 13:22:45 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E957D7A5 for ; Tue, 8 Aug 2023 09:09:28 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow1.mail.gandi.net (Postfix) with ESMTP id AF130D2EBB for ; Tue, 8 Aug 2023 06:29:47 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id DBBD3240002; Tue, 8 Aug 2023 06:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691476184; 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=0vlOW+m6/kgqn3cxpsCF/6Z4kqpXbg8aetH5L3Z+xlI=; b=iGc2YmhmqE/9pFacAlXbsSl1cEtqhFZPhTuggjUxgr/Z9u1JwecUCV+uGcyN34M3PKAkFb I07Uy10PS0y4HtlAEgonl+2DnXhN/pT8ccl2dTOSmNAtGswabVUHNVQ7wsf+nwA457WSLv s7mFrI4hml6cuTzyyJmen/Rb43kxc662ZQQcHtdsfRwqfD+kGaHH+zGJ9GLLL2o6v7Ni7w njMsZIFKjtNi8o+5aWtUWLDlvfd3VqSDDOs/k3UBFkxWVL84YtfLTQfy6rav44DHqEX/o2 Q81GfG8+gXqHTOMvMFhD73wFUFdR2VMxWd7DhKzjebQpG3zGE3LNtkoXQ5RYdw== From: Miquel Raynal To: Srinivas Kandagatla Cc: Greg Kroah-Hartman , Thomas Petazzoni , Robert Marko , Luka Perkov , Michael Walle , , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Miquel Raynal Subject: [PATCH v9 7/7] nvmem: core: Expose cells through sysfs Date: Tue, 8 Aug 2023 08:29:32 +0200 Message-Id: <20230808062932.150588-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808062932.150588-1-miquel.raynal@bootlin.com> References: <20230808062932.150588-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773688400312050544 X-GMAIL-MSGID: 1773688400312050544 The binary content of nvmem devices is available to the user so in the easiest cases, finding the content of a cell is rather easy as it is just a matter of looking at a known and fixed offset. However, nvmem layouts have been recently introduced to cope with more advanced situations, where the offset and size of the cells is not known in advance or is dynamic. When using layouts, more advanced parsers are used by the kernel in order to give direct access to the content of each cell, regardless of its position/size in the underlying device. Unfortunately, these information are not accessible by users, unless by fully re-implementing the parser logic in userland. Let's expose the cells and their content through sysfs to avoid these situations. Of course the relevant NVMEM sysfs Kconfig option must be enabled for this support to be available. Not all nvmem devices expose cells. Indeed, the .bin_attrs attribute group member will be filled at runtime only when relevant and will remain empty otherwise. In this case, as the cells attribute group will be empty, it will not lead to any additional folder/file creation. Exposed cells are read-only. There is, in practice, everything in the core to support a write path, but as I don't see any need for that, I prefer to keep the interface simple (and probably safer). The interface is documented as being in the "testing" state which means we can later add a write attribute if though relevant. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 117 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 32d9973df90b..11b9e5cc0b45 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -43,6 +43,7 @@ struct nvmem_device { struct gpio_desc *wp_gpio; struct nvmem_layout *layout; void *priv; + bool sysfs_cells_populated; }; #define to_nvmem_device(d) container_of(d, struct nvmem_device, dev) @@ -327,6 +328,43 @@ static umode_t nvmem_bin_attr_is_visible(struct kobject *kobj, return nvmem_bin_attr_get_umode(nvmem); } +static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, + const char *id, int index); + +static ssize_t nvmem_cell_attr_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t pos, size_t count) +{ + struct nvmem_cell_entry *entry; + struct nvmem_cell *cell = NULL; + size_t cell_sz, read_len; + void *content; + + entry = attr->private; + cell = nvmem_create_cell(entry, entry->name, 0); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + if (!cell) + return -EINVAL; + + content = nvmem_cell_read(cell, &cell_sz); + if (IS_ERR(content)) { + read_len = PTR_ERR(content); + goto destroy_cell; + } + + read_len = min_t(unsigned int, cell_sz - pos, count); + memcpy(buf, content + pos, read_len); + kfree(content); + +destroy_cell: + kfree_const(cell->id); + kfree(cell); + + return read_len; +} + /* default read/write permissions */ static struct bin_attribute bin_attr_rw_nvmem = { .attr = { @@ -348,11 +386,21 @@ static const struct attribute_group nvmem_bin_group = { .is_bin_visible = nvmem_bin_attr_is_visible, }; +/* Cell attributes will be dynamically allocated */ +static struct attribute_group nvmem_cells_group = { + .name = "cells", +}; + static const struct attribute_group *nvmem_dev_groups[] = { &nvmem_bin_group, NULL, }; +static const struct attribute_group *nvmem_cells_groups[] = { + &nvmem_cells_group, + NULL, +}; + static struct bin_attribute bin_attr_nvmem_eeprom_compat = { .attr = { .name = "eeprom", @@ -408,6 +456,69 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); } +static int nvmem_dev_populate_sysfs_cells(struct device *dev, void *data) +{ + struct nvmem_device *nvmem = to_nvmem_device(dev); + struct bin_attribute **cells_attrs, *attrs; + struct nvmem_cell_entry *entry; + unsigned int ncells = 0, i = 0; + int ret = 0; + + mutex_lock(&nvmem_mutex); + + if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) { + nvmem_cells_group.bin_attrs = NULL; + goto unlock_mutex; + } + + /* Allocate an array of attributes with a sentinel */ + ncells = list_count_nodes(&nvmem->cells); + cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1, + sizeof(struct bin_attribute *), GFP_KERNEL); + if (!cells_attrs) { + ret = -ENOMEM; + goto unlock_mutex; + } + + attrs = devm_kcalloc(&nvmem->dev, ncells, sizeof(struct bin_attribute), GFP_KERNEL); + if (!attrs) { + ret = -ENOMEM; + goto unlock_mutex; + } + + /* Initialize each attribute to take the name and size of the cell */ + list_for_each_entry(entry, &nvmem->cells, node) { + sysfs_bin_attr_init(&attrs[i]); + attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL, + "%s@%x", entry->name, + entry->offset); + attrs[i].attr.mode = 0444; + attrs[i].size = entry->bytes; + attrs[i].read = &nvmem_cell_attr_read; + attrs[i].private = entry; + if (!attrs[i].attr.name) { + ret = -ENOMEM; + goto unlock_mutex; + } + + cells_attrs[i] = &attrs[i]; + i++; + } + + nvmem_cells_group.bin_attrs = cells_attrs; + + ret = devm_device_add_groups(&nvmem->dev, nvmem_cells_groups); + if (ret) + goto unlock_mutex; + + nvmem->sysfs_cells_populated = true; + +unlock_mutex: + mutex_unlock(&nvmem_mutex); + + return ret; +} + #else /* CONFIG_NVMEM_SYSFS */ static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, @@ -2193,6 +2304,12 @@ static int nvmem_notifier_call(struct notifier_block *notifier, if (ret) return notifier_from_errno(ret); +#ifdef CONFIG_NVMEM_SYSFS + ret = nvmem_for_each_dev(nvmem_dev_populate_sysfs_cells); + if (ret) + return notifier_from_errno(ret); +#endif + return NOTIFY_OK; }