From patchwork Mon Aug 7 08:24:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131765 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1325765vqr; Mon, 7 Aug 2023 02:25:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERapCxfEEByAPkh03i0x0+km5Y6n1mD4f8RbNLoLxNlBzNMBXGZApq8gkstCZ1Tgw+OsHd X-Received: by 2002:a17:90a:6fe4:b0:262:f449:4497 with SMTP id e91-20020a17090a6fe400b00262f4494497mr8262494pjk.2.1691400326643; Mon, 07 Aug 2023 02:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691400326; cv=none; d=google.com; s=arc-20160816; b=h7P5GQgXQQdVB7A7iQMLyIEUNa8Z6gc8zBBXDslTZnHlTHHxoanUs+fa5k00rXRnXP IEKxB5txYARQJwzKMvDJxD4UV3ECz2m7BPdE25ybJ1RgFN+RaQUhlpFGXSOGeihvL1J6 ehCUKJM2ieIHb4gcJcH43M7n+WpqfDM5pHdhc5U+TwDFZ1e8qFxxqtABmmG6993vWxqh 1Fl+XtuqivtfX4aBOWxSnLohKbaAdakLvxYLeOdXs/IxBpSnjIKoF/vu6Cxze6sycCOF T9wa7liIJsR8EX7Maz2BW+E3W8BNZOous5p5AXKnmGyuEmQgukoh1VAhY+CHVp6J2gBJ k5XQ== 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=fSeYwoj7Ga2U1yXxyWdbFh6QBpq6OijV1L2S329ZGLx3gnKAMa6hefIKvCuwGNFCYm AvOzZwlfnl7Krl1QFyugMivA1KaJ6tzBH8u36RMRB3BKTZV5qQ4h78RCK9Rk1uvpCsiX BUbcexlsgBburNufORfbKJMDN73TjQE6bAlZirhzaOEKj8sQBHCquKdl+XHrH/JwRI3J uLGwIahbuOxwUw8tKVv5V9IEk666RZBzOKibJIExc4ZQM51DK3BBMl3ErGYJOnzTHiCe HSK7X8S0P39SGUhatA6SzTEc+OTS1Q9s3Xe1Tl+NM1vTCEd9iLe8a9NpNaBjpmCIqrzJ 4DKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YfPsMOia; 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 s3-20020a17090a5d0300b0026958c3d255si1509810pji.126.2023.08.07.02.25.12; Mon, 07 Aug 2023 02:25:26 -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=YfPsMOia; 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 S231195AbjHGIYc (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231160AbjHGIY2 (ORCPT ); Mon, 7 Aug 2023 04:24:28 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0BD1170A for ; Mon, 7 Aug 2023 01:24:25 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 08C17E0005; Mon, 7 Aug 2023 08:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396662; 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=YfPsMOia1mh7NlZNTd0z0v90XmIyRDVUTiXx0sWbBjHNy62wGwzTEZn9Czg/FN6L7wf6bb W+Xvc0gkWGhrCW2nBx7wj1JbhEDOpVAKSEpbhENhkq4g2Omw+cpUtJGoGiDMVNvKBkBqeq aEG57kS+oL7xgV/5h36ZWBzIvXSrdn0b1czkCG+H4t9gjVaqy3yLbV0/G6FURf688/PTcR zu1C+ApkGO6ypeueKTGNgNEXDGfEuOdTl21Bu2Qcjj+1LC20E6JyFYak7vcGswajX8tvKp KJ9vuqCAlM+djtj43n3jFeoOe4Lc9mz7cqB8XtDB2x8kBA2OCCBkLlMwe+9Reg== 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 v8 1/8] nvmem: core: Create all cells before adding the nvmem device Date: Mon, 7 Aug 2023 10:24:12 +0200 Message-Id: <20230807082419.38780-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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 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: 1773561788828932949 X-GMAIL-MSGID: 1773561788828932949 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 Mon Aug 7 08:24:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1325418vqr; Mon, 7 Aug 2023 02:24:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYTkX3J1BF8jHPXuDM2NqhvejCZVyBKzXDuRJK3g+tMBfjSfAOOqeB/8O4r+UkHWwRy4FC X-Received: by 2002:a05:6a20:6a0c:b0:13f:8e07:7ed4 with SMTP id p12-20020a056a206a0c00b0013f8e077ed4mr7573333pzk.13.1691400274563; Mon, 07 Aug 2023 02:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691400274; cv=none; d=google.com; s=arc-20160816; b=ds9PPXdYk06ORi8lPRgjOnfSQLjdQB/LRPgcMXIJfAxIEzRdoeS4j5yDSrTxWH9xmQ VVwO0cuIzOyVayUheq69ExtsEUm0rFg6QOYsDz7yT4wgH0SkGGC7C34p2x+NRUts2Zi0 0C7K38QxPYLIhR+eOrbNTtVFEU7Cy68Xf+fg4am9jWCaOsGEE0TnahzT7MACqIUvSZlI TrLi0GHOc+U0EmctJwUvAvF+Gfq2m60jTt7M/vBszzTCadX7W0utFJ08+AkkMBmmLsLa K21Ma6RVCZxusKiltZpqqce/khfqo6kAkqZVLefjTVOfkyu+3qZHcEbz2uk4n1hH/mrg cQwg== 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=Odz3GOHh/jKUsD+3m9e+zXc7EIWHTee63Nr9Y9sD8ajZmCVhyyjBvdlOSG/D+sYB+0 AARc8uIh3G+huoSUBkLJbRRH07h/jVJIDlLz17ejo/iqqs7HsGRQeq6rq4lN9A2b20sz yyG3tnPlxyqqkkLUOIsquVkJHh6ZbvVcQyw3ZSIvmMe4Bi/zWzCj/ta63kGPMrToSkXK G5r9SOozOSVEU19zyvWLL1RUeeHrVxyLYYo/3ibrRTR2ChWwG2RjdijzUQG/wWxfZl3C rm6KuNAG2D+6enU2lKwKq1ARfQ39vmiFEEtNeGPzhexiLdCRH5YyEJqjyTH+SByRW2Oy +YVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=h9ITThFr; 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 d19-20020a637353000000b0054f93b261cfsi5163171pgn.88.2023.08.07.02.24.21; Mon, 07 Aug 2023 02:24:34 -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=h9ITThFr; 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 S231171AbjHGIY3 (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230415AbjHGIY1 (ORCPT ); Mon, 7 Aug 2023 04:24:27 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0A5A10EF for ; Mon, 7 Aug 2023 01:24:25 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 0A4D8E0006; Mon, 7 Aug 2023 08:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396664; 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=h9ITThFrDAL4gw+CgsF85+DiojEI16eg8zukQy7IymB5qM5FbBKLO6ipVnaRE6SacEkjhR 7L5nvgEVIMngiuqj/R8yhL2FvmRtjUJnhhYZfLNxW+991cKBuKouJdVzRP1qABsEAgC+56 kfcX22kxvOX2XfiHYyEi5tHD4QzMsbGm9szl+2N/eau5vaDcv9xD/th32j7JuWEfzJrZ1J ZvXqBfnkzJczCDU6Qc8zrnVeaDDvmugqDscjpfUUQGKESVtse+EkpWp+noLVd8woI39s8b K2kZLQh7PjdPV9Uw98gWvYnAGFsQmefUbD6gnompMMStJg+FTKDL7WpoD3SrGg== 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 v8 2/8] nvmem: core: Return NULL when no nvmem layout is found Date: Mon, 7 Aug 2023 10:24:13 +0200 Message-Id: <20230807082419.38780-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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 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: 1773561734580285193 X-GMAIL-MSGID: 1773561734580285193 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 Mon Aug 7 08:24:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1311041vqr; Mon, 7 Aug 2023 01:50:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCjj4dA3s2YOrEjYIUpg40fcdVNdBoCD3RyzA/1Vn4djF669DcqjHyHbU4eas0eznOzrsa X-Received: by 2002:a05:6a00:2d0f:b0:67a:8f2a:2cb2 with SMTP id fa15-20020a056a002d0f00b0067a8f2a2cb2mr8471846pfb.20.1691398241397; Mon, 07 Aug 2023 01:50:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691398241; cv=none; d=google.com; s=arc-20160816; b=cAxSGBVEZ2w4CU/9luhD7H22l/3amMQKe/wI7cV0ot3VtOTcBZuKaBfTaDPXjbLWJG f5Qrm1Pfdx+cvH8VUeGwcVqy19oy0430A24AvQemH90eG7gFfK1xNqNvJGhCm4io9EWN JTy49sBHqkE4lyGM7ZKiJnCzz4b9Hb7uy8AziGhiWRa+5HAG20wXPDvw/c1qeVHjko7M n9wkrGlP1056XDoUJrRTf1YC5rWQM93GcDIxa/4wiujoowYu1jthx6M5JrQXFAqtQTej bDX1Po9+mCap7tmo+P74qsthl3iQ+xq9L4c0MjTAYHUSMZ8jsHCk4nruzw2CN/y9W4uH zTyA== 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=r/GyzYb3FgKbWxtYhqzFKdh8SP1zoG9s95mmKcE0/drlxBuyOEa8LGn8ZTkgUJvDCG faUX7HHm+fyBbpnzKXGs9+Oy83qqIoD0la1X/dMRVFVBJ9XD5Vkykj7nW/nH4pE5y8+E 8d/Kp3Goq8shoSZ22jj+pezAYhBeD7Pwwj2Dmaa/KYwogm+tKdPwgsoaN9OSmoGQ+3WD Azywprl5QmV65V8zgrqEFRWyqzH3ZEDwVD2ATuPcGW1dnjAzRFViNHgbaaW7zP5CF/bW lsJmAPg9IJah/02LcIPQ2EtbRcGCA3PxEG6QQ+xl0eJHKvevU1rLKlt9ZyRG/6AtbYXQ nNuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nYNjKgZo; 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 y18-20020a056a00191200b00687507df746si5508993pfi.170.2023.08.07.01.50.28; Mon, 07 Aug 2023 01:50:41 -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=nYNjKgZo; 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 S230415AbjHGIYf (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbjHGIY2 (ORCPT ); Mon, 7 Aug 2023 04:24:28 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47CE1708 for ; Mon, 7 Aug 2023 01:24:26 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5F056E0002; Mon, 7 Aug 2023 08:24:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396665; 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=nYNjKgZojkY01P0C3FHtSizaXI7pck8xMwF4KtpouU1pc5Ba06KmbaRp25HKsflW9S1/gz 5YL15TmIXUdkZYYmJHBDGSYtdYKD6wYl8EOIjaFqVPS8qLHooCa0gNKnnLhe3jbN5i8YCs vFS/8AfxHvvY9C8vlYJBjaIWEUlto7xEC+v5dkCk3YgQJJxFUe8J9vDQGAc5Vima++G1HT vX6eVtCqBXTesRK2qiCWWBvevHVQEwaybQag2pnboyAXxWHsbgOp4+HUf/rmTiTEXbVkwi fsTo7Z10z6TfjLzCe52VfhbDV26zO/BnE7UUPo4GNekFjH6qu+AjnYeyqMToJQ== 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 v8 3/8] nvmem: core: Do not open-code existing functions Date: Mon, 7 Aug 2023 10:24:14 +0200 Message-Id: <20230807082419.38780-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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: 1773559602663114596 X-GMAIL-MSGID: 1773559602663114596 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 Mon Aug 7 08:24:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131744 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1307890vqr; Mon, 7 Aug 2023 01:42:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5swaaeMZs9ARBnl7hVtGgkPqXQwddwjptStd6EFML1JkVs5tLNRZf554/9pRLgsTbbi1E X-Received: by 2002:a05:6512:1598:b0:4fb:8bea:f5f6 with SMTP id bp24-20020a056512159800b004fb8beaf5f6mr7095766lfb.34.1691397732916; Mon, 07 Aug 2023 01:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691397732; cv=none; d=google.com; s=arc-20160816; b=WEaw6eIfn0WLnuZ9BizBiKh+rD403smajInZZNTOFSWbAQa8WRkwkjSCb3HiDitPQS AYf1k0bonYf3ZpyA0sQSYDWf/RL0h/qBEU/tKjd6aGmPIH66NA6UucLQAaBthtqArkCj h4fnifZAYG6/7Z7IbrmOncUaQPcwyhZubvBJWkJF99ysQx+LQkxyBcSlFO5HmAsdagA/ cpXNFAqCMbCkx+fI6t0rftbl6t13P9ElzuQzNA4THmhdnZdQOa2lZBnEgrt5YIhfVo8a 4SaOUI0koN/vhYPfrGay6YlZeX/gQCj+X+Ts794UK//wbjcwVBZZe73XmltNhtP8l7Re sF5w== 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=ZIUXjeBWaacBxz6WsBbjN0nfgEPspA1Ri8UkX9Lqn/c=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=l+wkWwwxdvfz5crQjdPRXqDr1iugbbyiQloEe94Cen1rkcjabYyC4Ioiq6y/M6bgux /2jgVNWJI5PUdQQARSMJsUgfE5QSlLTC8UcHpqrS5J6b4daSpzrc7WEWrPE0NPRv8w/K vj5iSFoFIDyGGRJYPuFiQxsqvNfiwuJHOsKmwJxE+7NsSUeEoaG6HfD/j5ieLxDVPDZF onKXwuRTKyVeXIJveFNeOMSQnIIqQXh7aW90ckHz4XFm3+mSrOT1hvZzONw7OjuHdACQ SsaCV5w2ejXLgMhSc9X+D/h/4WwnXLgEqtX8K1D0XTenBnPEBFacs1zARx8KjedzJC5V qu7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GJ4O90d8; 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 y15-20020aa7cccf000000b005233dc4703csi631985edt.604.2023.08.07.01.41.49; Mon, 07 Aug 2023 01:42:12 -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=GJ4O90d8; 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 S231237AbjHGIYi (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231164AbjHGIY2 (ORCPT ); Mon, 7 Aug 2023 04:24:28 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4A14170B for ; Mon, 7 Aug 2023 01:24:27 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8AB1BE0008; Mon, 7 Aug 2023 08:24:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396666; 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=ZIUXjeBWaacBxz6WsBbjN0nfgEPspA1Ri8UkX9Lqn/c=; b=GJ4O90d8uLjV6gqbzggm04xNN1c1GAYLfxnH+HXe4fc8uKvmeqmLg2Gb0nwcj/DbtJzC1q x4PxtNJ1tFCgghhyhgYx91lYmH+zvOFPRA5Z5wDRoqgpaFKzGWp1fBDiqBfmNA/c2KOgoX nEWMaI6auNK4sWQf41wVQ9AIuU2Yg8/IAwBHc/tOmQ+mdJZhexsbNBiRAJLfPZjFIzuSQ0 EloDDFHZrpo5r5QuNkC83vCRWWynLUskhZ3jPV7BO0bbg21bzIB+beNw1+NoV/tR51OnsD WgHwLsD7KgEh9av+dc8WvDMehvm9Shite7jUKGRSSvrNiTQn74hvqNzysQ/W2Q== 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 v8 4/8] nvmem: core: Track the registered devices Date: Mon, 7 Aug 2023 10:24:15 +0200 Message-Id: <20230807082419.38780-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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 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: 1773559069584341847 X-GMAIL-MSGID: 1773559069584341847 Create a list with all the NVMEM devices registered in the subsystem. This way we can iterate through them when needed (unused for now). Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 257328887263..4e81e0aaf433 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,9 @@ static LIST_HEAD(nvmem_cell_tables); static DEFINE_MUTEX(nvmem_lookup_mutex); static LIST_HEAD(nvmem_lookup_list); +static DEFINE_MUTEX(nvmem_devices_mutex); +static LIST_HEAD(nvmem_devices_list); + static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); static DEFINE_SPINLOCK(nvmem_layout_lock); @@ -1012,6 +1016,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; + mutex_lock(&nvmem_devices_mutex); + list_add_tail(&nvmem->node, &nvmem_devices_list); + mutex_unlock(&nvmem_devices_mutex); + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; @@ -1037,6 +1045,10 @@ static void nvmem_device_release(struct kref *kref) blocking_notifier_call_chain(&nvmem_notifier, NVMEM_REMOVE, nvmem); + mutex_lock(&nvmem_devices_mutex); + list_del(&nvmem->node); + mutex_unlock(&nvmem_devices_mutex); + if (nvmem->flags & FLAG_COMPAT) device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); From patchwork Mon Aug 7 08:24:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1335807vqr; Mon, 7 Aug 2023 02:52:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqN+4axLDUEapA/Bv0zJzqa8DyUfO5Wcp1bNz/BTB/8YukS+/Q2Vzy+2jY3x7OELs+YqcT X-Received: by 2002:a17:907:2717:b0:997:e7d0:e26d with SMTP id w23-20020a170907271700b00997e7d0e26dmr7428476ejk.4.1691401930874; Mon, 07 Aug 2023 02:52:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691401930; cv=none; d=google.com; s=arc-20160816; b=SlCbkLiQoj4IfjqYwX5J2kBBG5+Ysj2e7ZvKKsTflfLaohVfXkBWJHRYQyUeSY5jTT h6/QkkvxTRrH1vCh2yhKNzImIzdoAFIP+ajR0lVEBRmxVhKWkxMYyRwlGcAFrH+9WEFQ 6QU9i4ZFYGXky6iDVzh+DlwckKJ3W15ugYOw6MD/QtwO65RQi+MslICTOFNDNxJ0VhG5 ZPQjLQPwM04fl8V7xoDpldes+10JyhUx63ZABfvdVKjNrKjFIpFhe1mrfjrFHeB448RJ 2nR4FMWHo0KyS9Uh+iAvJSrzvjRFViQd9lRvzkhc1981rlKgCJrgkkBvamWUqIxU5C8s csHw== 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=J4dYHwL4Kcq6etObC2M6cBOZ7KmMlQzjfr2hw8SBaeU=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=vVIOsWnqtuhSDkjB9OT8eVrjELiIX8aahK5jWPwHpMqmirwT25k6/scvNxq7FH+7S9 qD2NrTBN4YK09W4iwKY1CA6i3mHoRve0+AXu1PIHsapRZpROYRIzWy//hPNZ+eI521D+ ouxhEhgSHFuE/KFnBJ+5f+xxtyCpPtGuVZugLHA6FxMWhul/52p3L6XrGqFJgJL2Mzj4 CpvbUT/ZuB8QMJATTzxZM2wGXgOpxvEctBNtVH8oIcMtlZEXH6OMPn31PxgSPTKBocPZ aONGC4rDZZjfUwRvh2p8Mtbm/JRgJ3Kw/K0dacDCr9N+/sEQ7KIuFTWLqv3UGKeGerqZ Nq3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=k0m+gdyJ; 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 j21-20020a17090643d500b009930d9d6b4csi5539304ejn.888.2023.08.07.02.51.46; Mon, 07 Aug 2023 02:52:10 -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=k0m+gdyJ; 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 S230206AbjHGIYl (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbjHGIYa (ORCPT ); Mon, 7 Aug 2023 04:24:30 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C814110EF for ; Mon, 7 Aug 2023 01:24:28 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 96901E0009; Mon, 7 Aug 2023 08:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396667; 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=J4dYHwL4Kcq6etObC2M6cBOZ7KmMlQzjfr2hw8SBaeU=; b=k0m+gdyJ6Vm0q6GmoAjRjCfBdOudPAv2IYDn0ESIIZv99751WKcNHURJbrFnlLN2QegL2X 8nFBg+SVsgeCYV5HM438lEg4vBk4pusSkGMCZp86WepN7lrWgpnAJTGrpUsCVAMtHIkqQn n+jTgPEXCtwiLnTp4gxQCOamku6BoiyArRG4GTO0uCLWwtdddoPGbox5reVhzk6HwxqWa/ 8pBJB0nkGHVuZ5HcrcyU4YnfgSShZaXhAohRNF7aH+tQGAb/xAMKHBlfJKF5XIRtH7wuft KoXKCvUzQGilbGrSlR26XLgpzU4zbAQs9/OE56ubIqf91dUsDhrXz8e/+MQw5Q== 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 v8 5/8] nvmem: core: Notify when a new layout is registered Date: Mon, 7 Aug 2023 10:24:16 +0200 Message-Id: <20230807082419.38780-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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: 1773563471417037633 X-GMAIL-MSGID: 1773563471417037633 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 4e81e0aaf433..0406fbc7b750 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -776,12 +776,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 Mon Aug 7 08:24:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1310993vqr; Mon, 7 Aug 2023 01:50:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFG8tjYrkYs45Qs4v5mv+ylcQognAwUa7Sipvm83mn3c6PJfRDOCa3MhK4qMeZ00JA9FMwd X-Received: by 2002:a05:6358:341d:b0:137:89ac:20d4 with SMTP id h29-20020a056358341d00b0013789ac20d4mr6523812rwd.18.1691398234206; Mon, 07 Aug 2023 01:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691398234; cv=none; d=google.com; s=arc-20160816; b=sCAFGqymXp+Bv7YNiJFQzJan1ZvBnVx3h+fS/jcpETjPU4meboSprpdkeLOc1uGo6k tKSk19m/XQMRd0Qlab+2SiJWmhAU+YPOK1EcjMe7BPD01+u03cX2iT6L2CLi3ZFygPeR gOqOhRItHQdEbw38g48nLpP31x80D/qmrtxwPx2GgLNGqMqmrT8Wr680b9CPxdJo88uF My82oTC7IVyyaqyMXS41lIYtsIf4Fh9ymX2oW/bnDbuZrT7LCNEuH3F43F99k1hrmIgY U70y3OkmjGClA7VPWC2uteLzhTBpFd9P4fqp+izl9F2dDKQYD/fq+sA2XgUPYYm2SSFI 9oGg== 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=oQ7q+S0WA0btHb97Zj7i/4YX+TmscMRWUDpKDDLHHz0=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=Ct1HJiNTilMqzGEqM5hlz3FzSHvc3yDNY6SATzJY4VARFYkoZNINwDrghyLgdqaMyg 6VHJqIQVLk7oY3M0VIwWsKvXYI4/iMAxmAvnnoM+Z9dxfeiYAEC+dd0qBt7ROnj5RZBX DqZY5Fhds1pKFNojKWcP/43Enk2hBq4Tc7uPxMx7SEg+3hetZVQEvBHKG99JDpXqpP0Q S42JYY5RoA412qGuI7HKaoyZtckb8Yu0YxQeOt9LbXj96cbPlLDXz+I88pGGGWiERHjA SmBvpHFdQBJaVuIjjGGs80tvuTgWjvbkayuWznZ6B1d3EefSAp4PZt1nYvzrQTPRk2R7 490Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XqFD2h4S; 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 d9-20020a63d649000000b0055bc086a118si5376732pgj.253.2023.08.07.01.50.21; Mon, 07 Aug 2023 01:50:34 -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=XqFD2h4S; 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 S231276AbjHGIYn (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231190AbjHGIYb (ORCPT ); Mon, 7 Aug 2023 04:24:31 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA8FF170A for ; Mon, 7 Aug 2023 01:24:29 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id B5EBDE0007; Mon, 7 Aug 2023 08:24:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396668; 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=oQ7q+S0WA0btHb97Zj7i/4YX+TmscMRWUDpKDDLHHz0=; b=XqFD2h4SHy90or4PHN6ihAb8LqwK6j9Hbtm77HM1DnMgJIR7h81TILlSsKASbc2TejCYDc cJ5qdXbsgReTISed192tNsSqXnZQc/28xsMou2Bhru45wokp7/csujF2Hg8JlIHbSOh+vN Km9co7BsbGYo7gOnoV8WePfs/sTwaEH660la/epu/171u5Nx5/kkgf36848k8RaRamfGpo qqf+lNKqEXUOWknQ36Zw7rBpys53X6e37e2UL889cLv2AOzwWzmr6f6hDHCXXBiEMlILTj PNhq0IR+jDY7mCc4e05c0OGIaAHtAePOkA77plwLQkVRIdcZd93dlo1x6s84/g== 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 v8 6/8] nvmem: core: Rework layouts to become platform devices Date: Mon, 7 Aug 2023 10:24:17 +0200 Message-Id: <20230807082419.38780-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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: 1773559594833803539 X-GMAIL-MSGID: 1773559594833803539 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 | 132 ++++++++++++++++++++++++------- drivers/nvmem/layouts/onie-tlv.c | 39 +++++++-- drivers/nvmem/layouts/sl28vpd.c | 39 +++++++-- include/linux/nvmem-provider.h | 11 +-- 4 files changed, 172 insertions(+), 49 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 0406fbc7b750..868a6f8b3227 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -80,6 +80,7 @@ static LIST_HEAD(nvmem_lookup_list); static DEFINE_MUTEX(nvmem_devices_mutex); static LIST_HEAD(nvmem_devices_list); +struct notifier_block nvmem_nb; static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); static DEFINE_SPINLOCK(nvmem_layout_lock); @@ -795,23 +796,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; @@ -868,7 +862,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; } @@ -887,6 +881,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) @@ -979,19 +974,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) @@ -1010,16 +992,21 @@ 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); + } + mutex_lock(&nvmem_devices_mutex); list_add_tail(&nvmem->node, &nvmem_devices_list); mutex_unlock(&nvmem_devices_mutex); @@ -1030,8 +1017,6 @@ 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: @@ -2137,13 +2122,100 @@ 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_try_matching_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) + goto put_layout; + + return 0; + +put_layout: + nvmem_layout_put(nvmem->layout); + return ret; +} + +/* + * 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, *tmp; + 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_try_matching_available_layout(nvmem); + if (ret) + return notifier_from_errno(ret); + + return NOTIFY_OK; + } + + /* NVMEM devices might be "waiting" for this layout */ + list_for_each_entry_safe(nvmem, tmp, &nvmem_devices_list, node) { + ret = nvmem_try_matching_available_layout(nvmem); + 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 Mon Aug 7 08:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1307256vqr; Mon, 7 Aug 2023 01:40:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEILrP1nwzpHulA5BvPTciYwHTBIwyo2wERs6CdUh4PMiicDE4Q6Z94diR1Xw+A8JG5qp3q X-Received: by 2002:a17:906:3150:b0:99b:c952:309a with SMTP id e16-20020a170906315000b0099bc952309amr6701115eje.39.1691397640370; Mon, 07 Aug 2023 01:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691397640; cv=none; d=google.com; s=arc-20160816; b=z0IanGB3/iMEjOxhTDEbexse3fvOavaMgyQnUATzPuz94J78hPlFVcxIeWo1m4mUQY jWvpj1Jtf3iGdtkL5c76h4KTBnS1J/fETNMh3hTOVN3PQIrPZV6Cs73V1vJ0aXpXCBtc eLmO/sLu7YeAD6RZU21xged5SEBJFhCqMNuaBDKC0IjDPLQCXfuBb6h7j/o8DgcSqhxt Z9t6+8nTfGFVrR0H8tQTU+U+qAQF1hbswJgtuz8XalVQ1cMsGKEyhu35UIoeg2XZUkFh K0aNfWQfe/e7z5zPaBUZdOpZhvv4FzsZmYhm5ugc17ICEjGus1gQH8xYvgiJvudJm7I/ GJ/w== 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=b033axWpkf5mwn/Mo7lVr+a0d+WjG56F/66RCrg3PpGwhPxly5c3jT7X8H8dl9Ur+F 89vZSTfRVHMYaj+4lDV4ZO02uU1UzyhL3X3EYg0jo4NhJayhEMsPYkEM0PDBCmCOfaT0 KFBaYFtRGeph4B5GLvghzcWEDIFSdPlU8r4PVbXvkeXW8uVpGbJNcYlPgL3bcGg7ELk0 NK+ARBzeufnUL+pL5XPR8/Eq1P8n4scdcz50zkT3ZmWupJhWG+I2AEpmNhXbt2Ej4hOB LiYugpIQzV85Lyvqq5nTD2EXX9HNBlmY19U09jr55Z5vc9SfKpbnA2xdOlWyhgtMYYaq zZjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=kjUDxNyS; 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 o5-20020a1709064f8500b0099bc79a3897si5810811eju.886.2023.08.07.01.40.16; Mon, 07 Aug 2023 01:40:40 -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=kjUDxNyS; 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 S230382AbjHGIYp (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231191AbjHGIYc (ORCPT ); Mon, 7 Aug 2023 04:24:32 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A9FD1721 for ; Mon, 7 Aug 2023 01:24:31 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id C3D50E000C; Mon, 7 Aug 2023 08:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396669; 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=kjUDxNyS0uxFR0kzo+cDIBNqOC7LUzEn02ykcHbnNSze025tvzy0QDcE4EGC619pvA9rLd Qw4G81M2oHmkRSfdPHeOGK0hnZT5oDWD/NMjHhpxR8VgKbfcHmMXfcdk3nVS6W/9ht0Ol3 7jwQaFF0HQrvZMZQqcmmDav2NYYW4jzbRLsmhWzh80IO7p8r2NkS5Ik6GPdyB6A771sO5e pxo8VfM8Gcq+mx6FCvGxTcIivij6NHOFwdfdUQJs7WxuvrjATWkio34auJm/CGnS4SBr6H n+J1V4Fjxh3+ZOkcOyWWK3a17Ea1x7a08QFR2sE+9oXaEXLQcpzyuGAug5q5JQ== 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 v8 7/8] ABI: sysfs-nvmem-cells: Expose cells through sysfs Date: Mon, 7 Aug 2023 10:24:18 +0200 Message-Id: <20230807082419.38780-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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 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: 1773558972001948490 X-GMAIL-MSGID: 1773558972001948490 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 Mon Aug 7 08:24:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 131747 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1310636vqr; Mon, 7 Aug 2023 01:49:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPkNdaTOBUS679Nl7Fu78kNaReBwA0f5BU8xAElLL8z8MhQQtamBwIkcX9MpACdeIlxTsU X-Received: by 2002:a17:903:1d1:b0:1bc:ee6:7f2e with SMTP id e17-20020a17090301d100b001bc0ee67f2emr8920757plh.53.1691398185818; Mon, 07 Aug 2023 01:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691398185; cv=none; d=google.com; s=arc-20160816; b=zir9tLC/nAVnI9uGbFVPM7PXHabw5cWgcPBJT5x6K5sHdT+s4UCAic/4Jj2AU3IRvk P4YTl4PBbq4+ywdENskjIWIVJpFga2zVVOgpO0OdQmmZBE9iiwuREXJ2U+zzpl7wsQGU AdD+qQY0HLHQpsbF8HJoxJbhmKFPElC1WBJLRi+eYFHszN7Qsk6W8Bvz+iyrrYVWGtIo qDf/DrBykSGtqGup/oubydt6NLdKD73s210vVPFWNJcx5+TSnfFZj+BSV4WNuqqcmNUA Go1E8ulorcce5Qnm84JXyfJ7MVipH7BaeZUDx7MTMcnvJNYuVdIyPF5G5j1WnJxf/3gD 0lqw== 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=rCauNFO9SrDOuExJMZI4tMGirS53XqpHUVP3XjS2zkY=; fh=OHS2tDwbcHt81zFnYeyYq8ynDfpjq+e2h9R20vebRfM=; b=a14MqTSK6Vsn5RsxkoIDv+7j1bF4zM1xl1wgl/wKBfYnWkUER3283GugYgg8REq/YL ECjJRyVdh2UC2+L4buNuy34TDgZRImI2yP3AQGutLiXaU4SLkenXehPknhBGpxTJhzD2 H0/3iKzN2CfnsO63gUuodhOmxniFKC7X4V6UZT60jNlvmjxPD3hZW7Sbu8FeLrTlDso0 LJqrnsu7xfWhPYwx+3eTvypG3Y5D/syqnHKvEFDb8EY4jFtxm5QuvkKmm6jGcsihNgnM oADWT0CJLqVECi+PWp6GTGlZsfg3rQ0TwKRtg4EXkbiEUCGuvj7t/zPrpFoVyx4l63tu h/aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="O/j8Sp6X"; 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 g3-20020a170902d1c300b001bbd0358ef7si5298034plb.518.2023.08.07.01.49.32; Mon, 07 Aug 2023 01:49:45 -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="O/j8Sp6X"; 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 S231316AbjHGIYs (ORCPT + 99 others); Mon, 7 Aug 2023 04:24:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231217AbjHGIYe (ORCPT ); Mon, 7 Aug 2023 04:24:34 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 107EA172A for ; Mon, 7 Aug 2023 01:24:31 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id 0623EE000A; Mon, 7 Aug 2023 08:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1691396670; 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=rCauNFO9SrDOuExJMZI4tMGirS53XqpHUVP3XjS2zkY=; b=O/j8Sp6X7pH05L+rkiYwJVeg2sTnOPYzTXi7xVOVd8KwIFi3KArMVU4z3EX1BpMKjRLjWl X7Uq+CjZnRBpPPJzR/TmwrrxIBWb7eG4hH5qTm3WRWagh1jRQcnCJPFtnqVy118qO+Oc4X LaHXpi0A0i9oEyzODd90KTcnM1ldWxaWrpnF2mFE7HQTnn96l1NzfdpzTdklRMp1c1LXxY 3iQfVhVEsZdbkj92ZjnJsailsWYm/Ab0nX/97UaeKk/RGKf1NKXiJoTrgnF0U6/AxjDt86 UElHEHpRerMoMjjRogHs79xAZbeKCzt4jLLXogils+driIGk2P8cz84iRmlUPA== 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 v8 8/8] nvmem: core: Expose cells through sysfs Date: Mon, 7 Aug 2023 10:24:19 +0200 Message-Id: <20230807082419.38780-9-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230807082419.38780-1-miquel.raynal@bootlin.com> References: <20230807082419.38780-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS 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: 1773559544089196857 X-GMAIL-MSGID: 1773559544089196857 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 | 113 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 868a6f8b3227..1f24f4e71159 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -330,6 +330,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 = { @@ -351,11 +388,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", @@ -411,6 +458,64 @@ static void nvmem_sysfs_remove_compat(struct nvmem_device *nvmem, device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); } +static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) +{ + 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_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); + +unlock_mutex: + mutex_unlock(&nvmem_mutex); + + return ret; +} + #else /* CONFIG_NVMEM_SYSFS */ static int nvmem_sysfs_setup_compat(struct nvmem_device *nvmem, @@ -2148,8 +2253,16 @@ static int nvmem_try_matching_available_layout(struct nvmem_device *nvmem) if (ret) goto put_layout; +#ifdef CONFIG_NVMEM_SYSFS + ret = nvmem_populate_sysfs_cells(nvmem); +#endif + if (ret) + goto del_cells; + return 0; +del_cells: + nvmem_device_remove_all_cells(nvmem); put_layout: nvmem_layout_put(nvmem->layout); return ret;