From patchwork Tue Mar 7 16:53:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65718 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542330wrd; Tue, 7 Mar 2023 09:01:32 -0800 (PST) X-Google-Smtp-Source: AK7set/J9iQTfxUgOQ3jRWq1K1jhJbSjlEyMGwex0kHIqqYwjOeP7H3i06Rcd5TCLCrwHiQsm6Br X-Received: by 2002:a17:907:a4c:b0:8b1:3d15:1e2c with SMTP id be12-20020a1709070a4c00b008b13d151e2cmr20071547ejc.9.1678208492580; Tue, 07 Mar 2023 09:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208492; cv=none; d=google.com; s=arc-20160816; b=q4K3MO2qXGgnH/Vk1vJ5oD5PjloyQWN0nUnbEZ6F7fwvqvY+HYE8o2Jh8PPgEPznxw MGoNuAeQkaBlwYAGrWemTzSGnoEaMo95W+KT7uK+ZftNdBEu3ZgN0wtfHCTWOswOtgPr MGfnFMebyJ1GdJvnvUFtmrJ6/m6LQIs0yBWzJzf2rjtpvPWs6bSuQ3X1PYB9WFtMLyPv yYGS5eIdoXJUxVX/at6Bx7avo9baWsoSGarirJCFe0wbLKeQuVdFhBclNKE2FGAb1vsf ks0wQ/REvzlPdPbMUkFVB0jCbg1F+c0zoCv60N3/rLsQ1O/KEvMQVpD85b9lCU2+2DME rkWA== 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=75hjPMNAGJRNOFAp/fyez5Ik1I1pAujO7NUPgauoYjM=; b=d5HKVhBLV5/32+tzzbRFd9GNp4vbJfbLFSJoLmwJrSKg366cTYeMfFkCkBpRtMPC/m 3qeeEeTPhIFQgWABbbLTSWEi71TV3fHG2I65OwkyIzu2uMt4oX0Ljr+0w90ldBm1cEZV oZeB/Piob2SlVXSX3DtUO16p/nf86aNn5Mh6sgqJmlk1EM0W288irl60ux1S4Xuaz2PF ZzqyxumzfZPpSG6NsIdIVGC5t2ictUWOI4Yv3q1C6sa7FTlnE2KglYUWHSdOEtsJCxRe JLcNgwCTBXYPEVny43E/UkWJ8+SZudeNF3J/pai3cexJXCyJGpggJPoQ5aTXblHyzC0X JU5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=oJ8WdyTt; 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 k24-20020a17090627d800b008d46bf1a668si13503384ejc.1002.2023.03.07.09.00.57; Tue, 07 Mar 2023 09:01:32 -0800 (PST) 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=oJ8WdyTt; 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 S229767AbjCGQ6e (ORCPT + 99 others); Tue, 7 Mar 2023 11:58:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbjCGQ5x (ORCPT ); Tue, 7 Mar 2023 11:57:53 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A077C90B65; Tue, 7 Mar 2023 08:54:12 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 8EDA5C0004; Tue, 7 Mar 2023 16:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208048; 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=75hjPMNAGJRNOFAp/fyez5Ik1I1pAujO7NUPgauoYjM=; b=oJ8WdyTtiPt9WWMz16kTM2WhUvDSZHnxiu7sHpQSkl5i0bNflhYyI//yPMsyOqEa3Ovytc ufbJQMzuPs3WMtvOd3ZVr1BIKia1t7Kog777gMDB7EtVZ+CAfs7z5X9+vHXY+v8km0+6rx nA+np7No6SxiRdjVnKxKlOzwk+W9hmdi32NaaoVU3F7NJjS96feL2RqRZf8Jna8lAmnKNx BneQfPRfZ+ADOFet9i3Zwl//RJO9aLaJqWvOenznN0C0P8CR6xioHfsG69UM7dvENd5DVc jlouF4ECATQGEsQFf3Oj1LwNVmyLsqS6sy1Btg1o0GIwmAAJV05py+d3wZQjYw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Stephen Boyd , Peter Chen , Rob Herring Subject: [PATCH v2 01/21] of: Fix modalias string generation Date: Tue, 7 Mar 2023 17:53:39 +0100 Message-Id: <20230307165359.225361-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729148529642781?= X-GMAIL-MSGID: =?utf-8?q?1759729148529642781?= The helper generating an OF based modalias (of_device_get_modalias()) works fine, but due to the use of snprintf() internally it needs a buffer one byte longer than what should be needed just for the entire string (excluding the '\0'). Most users of this helper are sysfs hooks providing the modalias string to users. They all provide a PAGE_SIZE buffer which is way above the number of bytes required to fit the modalias string and hence do not suffer from this issue. There is another user though, of_device_request_module(), which is only called by drivers/usb/common/ulpi.c. This request module function is faulty, but maybe because in most cases there is an alternative, ULPI driver users have not noticed it. In this function, of_device_get_modalias() is called twice. The first time without buffer just to get the number of bytes required by the modalias string (excluding the null byte), and a second time, after buffer allocation, to fill the buffer. The allocation asks for an additional byte, in order to store the trailing '\0'. However, the buffer *length* provided to of_device_get_modalias() excludes this extra byte. The internal use of snprintf() with a length that is exactly the number of bytes to be written has the effect of using the last available byte to store a '\0', which then smashes the last character of the modalias string. Provide the actual size of the buffer to of_device_get_modalias() to fix this issue. Note: the "str[size - 1] = '\0';" line is not really needed as snprintf will anyway end the string with a null byte, but there is a possibility that this function might be called on a struct device_node without compatible, in this case snprintf() would not be executed. So we keep it just to avoid possible unbounded strings. Cc: Stephen Boyd Cc: Peter Chen Fixes: 9c829c097f2f ("of: device: Support loading a module with OF based modalias") Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index c674a13c3055..877f50379fab 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -297,12 +297,15 @@ int of_device_request_module(struct device *dev) if (size < 0) return size; - str = kmalloc(size + 1, GFP_KERNEL); + /* Reserve an additional byte for the trailing '\0' */ + size++; + + str = kmalloc(size, GFP_KERNEL); if (!str) return -ENOMEM; of_device_get_modalias(dev, str, size); - str[size] = '\0'; + str[size - 1] = '\0'; ret = request_module(str); kfree(str); From patchwork Tue Mar 7 16:53:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65744 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2552300wrd; Tue, 7 Mar 2023 09:17:21 -0800 (PST) X-Google-Smtp-Source: AK7set+/sPV8sHePhUhjPpJ8FAbMW4oXhFOYxsSGmy+f8nmuWUvJPi7HyybPSboUVM5BoP/uV2Xy X-Received: by 2002:a17:903:4cd:b0:19c:ed28:66ec with SMTP id jm13-20020a17090304cd00b0019ced2866ecmr13007320plb.21.1678209441271; Tue, 07 Mar 2023 09:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678209441; cv=none; d=google.com; s=arc-20160816; b=k3gwDIGLEXw6LFJTpG8+GrWsfJpxw9ACOArlPimAOW2KOn1ntD7g7TUPSF/WKwurnq Fod6WzB5HQIJpPAq1MUXaLhnWEBmg8W4PCdZoZWwhmOiUqlnxjMZd+7UjRHlmfm2M5CO 4vNAy+JqQowZYE2Kuvvdw4yu0lHjOiXrWIwimVvq5J+yeBVaTGMny4kKoXhOhQQRZOgC 00Bwga1Z0IDQWzu1ORR1a7g3xXm+Xx3s0c20endlLpBMYChQ6eUnxe8VSSCVviBcWE6X 6J8uqwfCgs+g8IXthuZbUWFCEELM1rEXPyFgKjG1UlNcaxxAAmfhSQrv1rL7+TBimjB+ 1ZtA== 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=Di4CkdLE13gZroWi0/GPKiH4AbmERRcM8yePy48y2K0=; b=TTGjH5SdEN/co5U2j3Q/tjJxT4i88ZrBVwgkXzLtAUrJ6whEAIRPkIgi2UAw/iO6h3 PySyl1mCy+e7p45dcVmYwfBsc0J6+S47uRWlY2sXBzyFNUl6cx0lXPxbZZslDB5DrFqA QyB79f82VHskspRP849d5r8k0hnlfv+0Qf0PXmxe1Zsozf4/mHiVLRjZP9Tf0mNwmYNV j+Ueg6rOZ8rscScGKAJbGVWZ8Qm445b0jzuQI08LMpKQ50h/IpWiAENsz0UFeeJ50MDY XAtoSTVRUu0PdLu6HI3rXGlkfx+VTCmQSvRZgVFcrlmlUvWOLofokgeiBcmbN4Nhe3bP vBUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="E/GTuqmP"; 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 p17-20020a1709028a9100b0019cd505cdd4si11929622plo.236.2023.03.07.09.17.09; Tue, 07 Mar 2023 09:17:21 -0800 (PST) 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="E/GTuqmP"; 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 S231159AbjCGQ6k (ORCPT + 99 others); Tue, 7 Mar 2023 11:58:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbjCGQ6B (ORCPT ); Tue, 7 Mar 2023 11:58:01 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262358EA35; Tue, 7 Mar 2023 08:54:17 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 01E90C000E; Tue, 7 Mar 2023 16:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208056; 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=Di4CkdLE13gZroWi0/GPKiH4AbmERRcM8yePy48y2K0=; b=E/GTuqmPdUJ/utpu0EW6+zW5IZCM7Pm/NvVPxTU9qQ0sSMS2fseZmz0FB8Wmy2Ndx9Bzkh dUzsy84pQ7LxlkKoEpx4nWrBTBCSDtdnqG2Cjlev8Ox7qxcZkEuUyqtELBkOhpilU0cm17 b7o6bjRQUAwa2IiiDqvg8VVwGrD04L3WcVeCxeTcMIO28/0CAFDTWtTSsnaG7kdHpSboZb ABjGpxlPTX72Km/od4XM/a26JL8k9Uzrex8s/4phg8TfJImQZne3iU2gl/d4Opg00yJrrV hQ6qH3fcuMs9IRgvyZ7GkG3G//xyycKDvCtXeWgdKM/WTyj0gd/e37YwpA928g== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 02/21] of: Update of_device_get_modalias() Date: Tue, 7 Mar 2023 17:53:40 +0100 Message-Id: <20230307165359.225361-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759730142941850250?= X-GMAIL-MSGID: =?utf-8?q?1759730142941850250?= This function only needs a "struct device_node" to work, but for convenience the author (and only user) of this helper did use a "struct device" and put it in device.c. Let's convert this helper to take a "struct device node" instead. This change asks for two additional changes: renaming it "of_modalias()" to fit the current naming, and moving it outside of device.c which will be done in a follow-up commit. Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 877f50379fab..2bbb67798916 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -248,7 +248,7 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) +static ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) { const char *compat; char *c; @@ -256,19 +256,16 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len ssize_t csize; ssize_t tsize; - if ((!dev) || (!dev->of_node)) - return -ENODEV; - /* Name & Type */ /* %p eats all alphanum characters, so %c must be used here */ - csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T', - of_node_get_device_type(dev->of_node)); + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', + of_node_get_device_type(np)); tsize = csize; len -= csize; if (str) str += csize; - of_property_for_each_string(dev->of_node, "compatible", p, compat) { + of_property_for_each_string(np, "compatible", p, compat) { csize = strlen(compat) + 1; tsize += csize; if (csize > len) @@ -293,7 +290,10 @@ int of_device_request_module(struct device *dev) ssize_t size; int ret; - size = of_device_get_modalias(dev, NULL, 0); + if (!dev || !dev->of_node) + return -ENODEV; + + size = of_modalias(dev->of_node, NULL, 0); if (size < 0) return size; @@ -304,7 +304,7 @@ int of_device_request_module(struct device *dev) if (!str) return -ENOMEM; - of_device_get_modalias(dev, str, size); + of_modalias(dev->of_node, str, size); str[size - 1] = '\0'; ret = request_module(str); kfree(str); @@ -321,7 +321,12 @@ EXPORT_SYMBOL_GPL(of_device_request_module); */ ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len) { - ssize_t sl = of_device_get_modalias(dev, str, len - 2); + ssize_t sl; + + if (!dev || !dev->of_node) + return -ENODEV; + + sl = of_modalias(dev->of_node, str, len - 2); if (sl < 0) return sl; if (sl > len - 2) @@ -386,8 +391,8 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) if (add_uevent_var(env, "MODALIAS=")) return -ENOMEM; - sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], - sizeof(env->buf) - env->buflen); + sl = of_modalias(dev->of_node, &env->buf[env->buflen-1], + sizeof(env->buf) - env->buflen); if (sl >= (sizeof(env->buf) - env->buflen)) return -ENOMEM; env->buflen += sl; From patchwork Tue Mar 7 16:53:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542650wrd; Tue, 7 Mar 2023 09:01:58 -0800 (PST) X-Google-Smtp-Source: AK7set/31dzk0J1zttf3UIaIOTBONXRLKb5DZOcuYlY9O2qoDOgR3J5bE5BWuzny8B28I3fnqMBR X-Received: by 2002:aa7:d714:0:b0:4a2:5f73:d3d2 with SMTP id t20-20020aa7d714000000b004a25f73d3d2mr12166800edq.41.1678208518310; Tue, 07 Mar 2023 09:01:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208518; cv=none; d=google.com; s=arc-20160816; b=UyyLBbKGp61WDkfoJBgbZ0uCbGL4UVr7PGnzEFq1G/OTzKIIBzc3LX3kLoFDeWmrWM lQZUZohQCVlDXAp5pGnQcX5YseUe+Q49NzSt+lggrmR9WloSpY1rxMTcx0n5gYsMHiGk pk5XPNybPyWD3njZApCYxJ1t23jWHR+bGdD7ipGx5LCk0edGAay8EubK0MpFk+4Jr4bN xdoFkg6rnFHQXh8BtDbo/s90P9CWxv8RmpcrcgWcsXLC7aT+XUOimprLJYjkkz5Jdi7c seYMvzV4RH4TUT3Qn3a664YZubOGthfnzubjZc3ODKHaArxnkKzCmsh43DCQ8aejLpV7 UvTg== 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=AydJWfzDv7AL2c1bg6r1qVLfZawbDxF4QfVTKj9aXJ8=; b=IFPr7P7kcTqNXwHMw5kPst/6G+kzeQ404LKGmWTODYd5U/urBdA6YcdAs+RdU6Dwuo O5z+2EVfHqNypGCoMvvBypsNjvqGhkQHXIMO+A+IKL1gILCHsPG+pyJ75WUJ0enhTywv JemDX7+jMeOi9AcUmsGIcXa0oWwhH7EF9G8YOPxctmBMzMHPQwlfj9DhwmjDxI3rIJVC Llsv1YDIMho0VFJPBUZKUiX4KlpgDzGgIcc6deb+1zHMc47dYvUt8yKgiE0ziqpHAC7T +zaWE3DSgHh8VEJx25uqjLcHSJgh2aoGz6DnwfTOrzyfasSrmVa/CKu3BAt1nUe93yHm LRbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=AHsGXlzY; 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 h4-20020a50ed84000000b004bfa2a3102asi14960538edr.458.2023.03.07.09.01.06; Tue, 07 Mar 2023 09:01:58 -0800 (PST) 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=AHsGXlzY; 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 S230056AbjCGQ6t (ORCPT + 99 others); Tue, 7 Mar 2023 11:58:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbjCGQ6E (ORCPT ); Tue, 7 Mar 2023 11:58:04 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BE8690B6C; Tue, 7 Mar 2023 08:54:24 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 057ACC0003; Tue, 7 Mar 2023 16:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208060; 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=AydJWfzDv7AL2c1bg6r1qVLfZawbDxF4QfVTKj9aXJ8=; b=AHsGXlzY3Nw33pWY6CJr1qEs8mDDyRKQGWt3GGuQ/gcRXvLeJcq+cliV15TR2f4+IaVPpK tw8nrnOuZWrwDRjLy6yy0er15hi/OTtOFIffXi/wrp/2OOzc7s7KbjsjcKuVvFLMDngfnm YwtUn4zCIH+x09s+U4gRDrJTpQvtwfciIh2K6kwaKJ9+7UFPReCrZwi4VAUL6ocnxoOM3f IL4nFf6aBIgiA86TW6bLVfIXayr761VarJKtbURSIcAYLD0X0T2BHdudGomlD1FPA49Cxl /Uv/6GhB03BEno8OwYhhObh68mnw81cWHXPSFTnkL0he97ToLcl/Cn/BazbKdw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , "Rafael J . Wysocki" , Len Brown , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sebastian Reichel , Wolfram Sang , Mark Brown Subject: [PATCH v2 03/21] of: Rename of_modalias_node() Date: Tue, 7 Mar 2023 17:53:41 +0100 Message-Id: <20230307165359.225361-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729175137032171?= X-GMAIL-MSGID: =?utf-8?q?1759729175137032171?= This helper does not produce a real modalias, but tries to get the "product" compatible part of the "vendor,product" compatibles only. It is far from creating a purely useful modalias string and does not seem to be used like that directly anyway, so let's try to give this helper a more meaningful name before moving there a real modalias helper (already existing under of/device.c). Also update the various documentations to refer to the strings as "aliases" rather than "modaliases" which has a real meaning in the Linux kernel. There is no functional change. Cc: Rafael J. Wysocki Cc: Len Brown Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: Sebastian Reichel Cc: Wolfram Sang Cc: Mark Brown Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring Acked-by: Sebastian Reichel # for HSI --- drivers/acpi/bus.c | 7 ++++--- drivers/gpu/drm/drm_mipi_dsi.c | 2 +- drivers/hsi/hsi_core.c | 2 +- drivers/i2c/busses/i2c-powermac.c | 2 +- drivers/i2c/i2c-core-of.c | 2 +- drivers/of/base.c | 15 ++++++++------- drivers/spi/spi.c | 4 ++-- include/linux/of.h | 2 +- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 0c05ccde1f7a..6eea487a1de6 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -817,9 +817,10 @@ static bool acpi_of_modalias(struct acpi_device *adev, * @modalias: Pointer to buffer that modalias value will be copied into * @len: Length of modalias buffer * - * This is a counterpart of of_modalias_node() for struct acpi_device objects. - * If there is a compatible string for @adev, it will be copied to @modalias - * with the vendor prefix stripped; otherwise, @default_id will be used. + * This is a counterpart of of_alias_from_compatible() for struct acpi_device + * objects. If there is a compatible string for @adev, it will be copied to + * @modalias with the vendor prefix stripped; otherwise, @default_id will be + * used. */ void acpi_set_modalias(struct acpi_device *adev, const char *default_id, char *modalias, size_t len) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index 497ef4b6a90a..0f0a715704ba 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -160,7 +160,7 @@ of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node) int ret; u32 reg; - if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) { + if (of_alias_from_compatible(node, info.type, sizeof(info.type)) < 0) { drm_err(host, "modalias failure on %pOF\n", node); return ERR_PTR(-EINVAL); } diff --git a/drivers/hsi/hsi_core.c b/drivers/hsi/hsi_core.c index 884066109699..8066e31bbece 100644 --- a/drivers/hsi/hsi_core.c +++ b/drivers/hsi/hsi_core.c @@ -207,7 +207,7 @@ static void hsi_add_client_from_dt(struct hsi_port *port, if (!cl) return; - err = of_modalias_node(client, name, sizeof(name)); + err = of_alias_from_compatible(client, name, sizeof(name)); if (err) goto err; diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c index 2e74747eec9c..ec706a3aba26 100644 --- a/drivers/i2c/busses/i2c-powermac.c +++ b/drivers/i2c/busses/i2c-powermac.c @@ -284,7 +284,7 @@ static bool i2c_powermac_get_type(struct i2c_adapter *adap, */ /* First try proper modalias */ - if (of_modalias_node(node, tmp, sizeof(tmp)) >= 0) { + if (of_alias_from_compatible(node, tmp, sizeof(tmp)) >= 0) { snprintf(type, type_size, "MAC,%s", tmp); return true; } diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index 3ed74aa4b44b..df21c2b69bed 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c @@ -27,7 +27,7 @@ int of_i2c_get_board_info(struct device *dev, struct device_node *node, memset(info, 0, sizeof(*info)); - if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) { + if (of_alias_from_compatible(node, info->type, sizeof(info->type)) < 0) { dev_err(dev, "of_i2c: modalias failure on %pOF\n", node); return -EINVAL; } diff --git a/drivers/of/base.c b/drivers/of/base.c index d5a5c35eba72..fd98a302a07f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1208,19 +1208,20 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from, EXPORT_SYMBOL(of_find_matching_node_and_match); /** - * of_modalias_node - Lookup appropriate modalias for a device node + * of_alias_from_compatible - Lookup appropriate alias for a device node + * depending on compatible * @node: pointer to a device tree node - * @modalias: Pointer to buffer that modalias value will be copied into - * @len: Length of modalias value + * @modalias: Pointer to buffer that alias value will be copied into + * @len: Length of alias value * * Based on the value of the compatible property, this routine will attempt - * to choose an appropriate modalias value for a particular device tree node. + * to choose an appropriate alias value for a particular device tree node. * It does this by stripping the manufacturer prefix (as delimited by a ',') * from the first entry in the compatible list property. * * Return: This routine returns 0 on success, <0 on failure. */ -int of_modalias_node(struct device_node *node, char *modalias, int len) +int of_alias_from_compatible(struct device_node *node, char *alias, int len) { const char *compatible, *p; int cplen; @@ -1229,10 +1230,10 @@ int of_modalias_node(struct device_node *node, char *modalias, int len) if (!compatible || strlen(compatible) > cplen) return -ENODEV; p = strchr(compatible, ','); - strscpy(modalias, p ? p + 1 : compatible, len); + strscpy(alias, p ? p + 1 : compatible, len); return 0; } -EXPORT_SYMBOL_GPL(of_modalias_node); +EXPORT_SYMBOL_GPL(of_alias_from_compatible); /** * of_find_node_by_phandle - Find a node given a phandle diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 3cc7bb4d03de..e4447ae59892 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2333,8 +2333,8 @@ of_register_spi_device(struct spi_controller *ctlr, struct device_node *nc) } /* Select device driver */ - rc = of_modalias_node(nc, spi->modalias, - sizeof(spi->modalias)); + rc = of_alias_from_compatible(nc, spi->modalias, + sizeof(spi->modalias)); if (rc < 0) { dev_err(&ctlr->dev, "cannot find modalias for %pOF\n", nc); goto err_out; diff --git a/include/linux/of.h b/include/linux/of.h index 98c252d2d851..fc7ada57df33 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -362,7 +362,7 @@ extern int of_n_addr_cells(struct device_node *np); extern int of_n_size_cells(struct device_node *np); extern const struct of_device_id *of_match_node( const struct of_device_id *matches, const struct device_node *node); -extern int of_modalias_node(struct device_node *node, char *modalias, int len); +extern int of_alias_from_compatible(struct device_node *node, char *alias, int len); extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args); extern int __of_parse_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name, int cell_count, From patchwork Tue Mar 7 16:53:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65719 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542531wrd; Tue, 7 Mar 2023 09:01:49 -0800 (PST) X-Google-Smtp-Source: AK7set8A745QraDJmHHK0LPdYlogrDLZo8MSq7h7Mx1Wl3njqY0/+JMnHjgLKylcsmDii+oBew4o X-Received: by 2002:a17:906:dd7:b0:87e:a34b:9e2b with SMTP id p23-20020a1709060dd700b0087ea34b9e2bmr15418467eji.28.1678208509018; Tue, 07 Mar 2023 09:01:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208509; cv=none; d=google.com; s=arc-20160816; b=H8mNBjeQpHz99En4DMQUd5YmhZmJeLI5ZRInXQZqpnC5qQxbVOed/bOqj7lb2wcOGp jhkDMZu22/EFb2snxY6ncMZG1+zdnR/PVNO6v8OtXwBmhlJhd1W5S62+L3/0h9iyEzzl hTvqT3O8MZv6rFLfNhiO+6h3WQMYeyqETXHFmYPERiM56Rs3DRPzc/kSsX/o2mcrQZpB mQsO+LxFnHrodG3BMxAYbuZREd7mksdIqagRDnl45yDTWUt4mpJ04szJSDTIOMofiRjb N8aEkAv5Mrlh2v7TOEUM9lEAY/9CCky+h0xXBgZIFC63bUe/Y7TSSpxuSNyy9FysE6l1 Xoog== 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=XRL047YAbIJguRiFQI3/XABhDSXRrCi4d0RTrfTbjWU=; b=z+x7I0GBoFw9NZfUzFBcyhNtdIeYqHFZouM6F/i0CLQ+E95L4MCy4ZQLyDTjGXkNlr vJh24212d8/RP+tTTZEbdvPtQz1bI4wQYRY2OZZpl05OOsslvUoOCGDoML/6XgDtHBCD Em7fcxcteLqdkP5JAofUbQNMALMcv8QkJsD15cZbOgqwj8ZTeudDgxKCFloir3BikT2q rp3unjkSzrdqEq1WXx8GZAh2xQPjMxPN/pJYxKLskoIBdE9jRJ8dfCq480aKMiyVamFu MVoCRMimIWTv8YIrV6Cr2Iv0WRxtNdxceOJ/r4Q3FGe/tGKB0Gxz5V/DRP2DvzklZtd8 SFeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XwfFA3Hz; 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 m15-20020a1709066d0f00b008b1392f7c7bsi8183683ejr.770.2023.03.07.09.01.20; Tue, 07 Mar 2023 09:01:49 -0800 (PST) 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=XwfFA3Hz; 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 S231271AbjCGQ7A (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230144AbjCGQ6G (ORCPT ); Tue, 7 Mar 2023 11:58:06 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0694693105; Tue, 7 Mar 2023 08:54:27 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 5739AC0015; Tue, 7 Mar 2023 16:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208063; 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=XRL047YAbIJguRiFQI3/XABhDSXRrCi4d0RTrfTbjWU=; b=XwfFA3HzD7D5w6xV5PE/+L4y9CVoE964mOvQRDJP8t3jXof4NetHFzuu4MqJhbc1ZR153r c56UtJ/xP/K42XiVHrrKZ1JcN/z//ubPBIYlX9Px3iV+V3WOQJ0kOunENwqIMPmg3UrbQl X0OMcRYYLdYmQKz6zLo9ZzHDoIpxMUmNETjzb0C8bD0ixos9BoOO0uxZSMPDAlc5/t5jnm MJudPX2tDOxCVh4q895wJk3OrNo0EePej0noQ32VRF1SRpX1uMpGDR4qCiMW4xbNwD8y2z JOBe485b7iUI1KcuOf7aD+hTBshLlpEWL80sLoO9CZCDZ1J8LyQqzEwSe9bqJg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 04/21] of: Move of_modalias() to module.c Date: Tue, 7 Mar 2023 17:53:42 +0100 Message-Id: <20230307165359.225361-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729165712597710?= X-GMAIL-MSGID: =?utf-8?q?1759729165712597710?= Create a specific .c file for of related module handling. Move of_modalias() inside as a first step. Suggested-by: Rob Herring Signed-off-by: Miquel Raynal --- drivers/of/Makefile | 2 +- drivers/of/device.c | 37 ------------------------------------- drivers/of/module.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 8 ++++++++ 4 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 drivers/of/module.c diff --git a/drivers/of/Makefile b/drivers/of/Makefile index e0360a44306e..ae9923fd2940 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y = base.o device.o platform.o property.o +obj-y = base.o device.o module.o platform.o property.o obj-$(CONFIG_OF_KOBJ) += kobj.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o obj-$(CONFIG_OF_FLATTREE) += fdt.o diff --git a/drivers/of/device.c b/drivers/of/device.c index 2bbb67798916..44f1f2ef12b7 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 -#include #include #include #include @@ -248,42 +247,6 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -static ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) -{ - const char *compat; - char *c; - struct property *p; - ssize_t csize; - ssize_t tsize; - - /* Name & Type */ - /* %p eats all alphanum characters, so %c must be used here */ - csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', - of_node_get_device_type(np)); - tsize = csize; - len -= csize; - if (str) - str += csize; - - of_property_for_each_string(np, "compatible", p, compat) { - csize = strlen(compat) + 1; - tsize += csize; - if (csize > len) - continue; - - csize = snprintf(str, len, "C%s", compat); - for (c = str; c; ) { - c = strchr(c, ' '); - if (c) - *c++ = '_'; - } - len -= csize; - str += csize; - } - - return tsize; -} - int of_device_request_module(struct device *dev) { char *str; diff --git a/drivers/of/module.c b/drivers/of/module.c new file mode 100644 index 000000000000..9c6a53f32c0f --- /dev/null +++ b/drivers/of/module.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Linux kernel module helpers. + */ + +#include +#include + +ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) +{ + const char *compat; + char *c; + struct property *p; + ssize_t csize; + ssize_t tsize; + + /* Name & Type */ + /* %p eats all alphanum characters, so %c must be used here */ + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', + of_node_get_device_type(np)); + tsize = csize; + len -= csize; + if (str) + str += csize; + + of_property_for_each_string(np, "compatible", p, compat) { + csize = strlen(compat) + 1; + tsize += csize; + if (csize > len) + continue; + + csize = snprintf(str, len, "C%s", compat); + for (c = str; c; ) { + c = strchr(c, ' '); + if (c) + *c++ = '_'; + } + len -= csize; + str += csize; + } + + return tsize; +} diff --git a/include/linux/of.h b/include/linux/of.h index fc7ada57df33..1372f8647272 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -373,6 +373,9 @@ extern int of_parse_phandle_with_args_map(const struct device_node *np, extern int of_count_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name); +/* module functions */ +extern ssize_t of_modalias(struct device_node *np, char *str, ssize_t len); + /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, @@ -730,6 +733,11 @@ static inline int of_count_phandle_with_args(const struct device_node *np, return -ENOSYS; } +static inline ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) +{ + return -ENODEV; +} + static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, const char *list_name, From patchwork Tue Mar 7 16:53:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542679wrd; Tue, 7 Mar 2023 09:01:59 -0800 (PST) X-Google-Smtp-Source: AK7set/p46GZ04b5LMhXs0LPPRsBI87Or/gdw0eMj5LcS/QKxeAlveLnUxq9gMgAwr7OFv4DVsbp X-Received: by 2002:a17:906:a882:b0:8aa:a802:adcd with SMTP id ha2-20020a170906a88200b008aaa802adcdmr13880774ejb.30.1678208519709; Tue, 07 Mar 2023 09:01:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208519; cv=none; d=google.com; s=arc-20160816; b=oJloDzQwqmZXEE1HZhPryEwt8ISeSHPRXpwVRaUYaC/CLExubXB40ph+BvUOHk97Di WEB4AlGOiD8hdl6JaxZrz4HhI0U6b7SPFOgYsw3p3Pj0k0kChpXy5qRY2eqUyQuIp5IY TmycZsRVr+8JwleG7qgPPXxDEncHRyGhlDDNoLh4oJdK4zHm8CbZU6hDtSLv9SjC77Gx d1e+Ps642z7yr/TwF7SYWX8ZDopbq1GKYsafbbVsMBtg45Z+BkjlDsstwhxLugWyIA3h QIZG+1ucPgI/KpU5OF4yqcB7MyfOk4LBeTsT5fLke2RJMDyjSCDb7aWgAWzTp4Zmc/Ta T0yg== 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=u1BxK7lQ9engNEKcMZlaGSCrOyuJ60v/1lMB8qEqy60=; b=nSqsWRcBNAIVFSWM7FA/wqO4zRmucnNgys0IPOBudBn2LyaFXNvmcWd0MYZ45K+N+9 5+6/WWp1W2G/PanuOs0T5KlW6YR14LCftgNFLe0h0bfhUqFXG78U0DKZ8qXGJMcUoqsG vy9PfN5rXM0/4hF9tzzXrO8F85KdRTQWFCa4A6u2Cv31Tma42XXkppEF7yKxjd2z0Zs9 gaT7NL64C2i3Bfw0MeCvw14GcDfgW5Z1onVI7HmIhLzKPTUgPEiHMT7M4wqjUd+Tn/xn f/ax0vlj9MVlE9o4noSAXwajrbR3xvBh0E5k7/U3x8qdWU7yRXm436B0D3w4ARtgn956 YZEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=c6i2mro1; 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 be5-20020a1709070a4500b008b7eed5fa1bsi992757ejc.737.2023.03.07.09.01.32; Tue, 07 Mar 2023 09:01:59 -0800 (PST) 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=c6i2mro1; 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 S230164AbjCGQ6x (ORCPT + 99 others); Tue, 7 Mar 2023 11:58:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjCGQ6E (ORCPT ); Tue, 7 Mar 2023 11:58:04 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A9F93122; Tue, 7 Mar 2023 08:54:26 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 12640C0008; Tue, 7 Mar 2023 16:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208065; 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=u1BxK7lQ9engNEKcMZlaGSCrOyuJ60v/1lMB8qEqy60=; b=c6i2mro1rqAAHI+67wZ1IUXXHxhvHB2uvzuaqeZqBxOurdJPS1Sd7ix9uiyADZ0VzGddGR i9FJfvr4UekAat2PUquaF0AKXkAplOpbF0R+L+22i+1xzgTmOtp9+MVSsGXSf7WmASXyyX oh1TIVd7vAwD8osamNFZZwceHF4mw50DStIrZEHD94daF48bnGvRR4h+dIu84KmlLGDOnz p73YD3P57BAvCSpofJ1WtoxxiAjSh+v31GmSN8SW3Ce1JM9TZOP6mHUQVdTpOOT7urIM6q SKrXe/6b7um8rOBvOLqZzaExX/+jZROqSt6anM7R5h7f5/tVdi6TmuWf6ujbYQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 05/21] of: Move the request module helper logic to module.c Date: Tue, 7 Mar 2023 17:53:43 +0100 Message-Id: <20230307165359.225361-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729177180265773?= X-GMAIL-MSGID: =?utf-8?q?1759729177180265773?= Depending on device.c for pure OF handling is considered backwards. Let's extract the content of of_device_request_module() to have the real logic under module.c. The next step will be to convert users of of_device_request_module() to use the new helper. Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 25 ++----------------------- drivers/of/module.c | 30 ++++++++++++++++++++++++++++++ include/linux/of.h | 6 ++++++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 44f1f2ef12b7..4bbb6e6388a9 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -8,7 +8,6 @@ #include /* for bus_dma_region */ #include #include -#include #include #include #include @@ -249,30 +248,10 @@ EXPORT_SYMBOL(of_device_get_match_data); int of_device_request_module(struct device *dev) { - char *str; - ssize_t size; - int ret; - - if (!dev || !dev->of_node) + if (!dev) return -ENODEV; - size = of_modalias(dev->of_node, NULL, 0); - if (size < 0) - return size; - - /* Reserve an additional byte for the trailing '\0' */ - size++; - - str = kmalloc(size, GFP_KERNEL); - if (!str) - return -ENOMEM; - - of_modalias(dev->of_node, str, size); - str[size - 1] = '\0'; - ret = request_module(str); - kfree(str); - - return ret; + return of_request_module(dev->of_node); } EXPORT_SYMBOL_GPL(of_device_request_module); diff --git a/drivers/of/module.c b/drivers/of/module.c index 9c6a53f32c0f..0cb3bb83b700 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -4,6 +4,7 @@ */ #include +#include #include ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) @@ -41,3 +42,32 @@ ssize_t of_modalias(struct device_node *np, char *str, ssize_t len) return tsize; } + +int of_request_module(struct device_node *np) +{ + char *str; + ssize_t size; + int ret; + + if (!np) + return -ENODEV; + + size = of_modalias(np, NULL, 0); + if (size < 0) + return size; + + /* Reserve an additional byte for the trailing '\0' */ + size++; + + str = kmalloc(size, GFP_KERNEL); + if (!str) + return -ENOMEM; + + of_modalias(np, str, size); + str[size - 1] = '\0'; + ret = request_module(str); + kfree(str); + + return ret; +} +EXPORT_SYMBOL_GPL(of_request_module); diff --git a/include/linux/of.h b/include/linux/of.h index 1372f8647272..692581486403 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -375,6 +375,7 @@ extern int of_count_phandle_with_args(const struct device_node *np, /* module functions */ extern ssize_t of_modalias(struct device_node *np, char *str, ssize_t len); +extern int of_request_module(struct device_node *np); /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, @@ -738,6 +739,11 @@ static inline ssize_t of_modalias(struct device_node *np, char *str, ssize_t len return -ENODEV; } +static inline int of_request_module(struct device_node *np) +{ + return -ENODEV; +} + static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, const char *list_name, From patchwork Tue Mar 7 16:53:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542545wrd; Tue, 7 Mar 2023 09:01:50 -0800 (PST) X-Google-Smtp-Source: AK7set+B6t0BN9HrxAZb0tTTJ780wItmqsn9xc4xJLvmuoOxZEp/sVIApbeTVYfV8l6uApwXkBUS X-Received: by 2002:a17:907:7604:b0:8de:e66a:ece9 with SMTP id jx4-20020a170907760400b008dee66aece9mr12071972ejc.24.1678208510312; Tue, 07 Mar 2023 09:01:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208510; cv=none; d=google.com; s=arc-20160816; b=jZKRrwd+eqD40AWfMOwvuMz1L2j/fNnu1pxlwo034Yf8/SpYLCZavuppsBcrlErqPV aeD1gPFolHOhBkOn0nmF5gEiF7yxQ/PMrkEZQuxo113wSrChIPLkbd/YyuUyLXnJwwR3 LAIDnreWf3kXo8eEzTlMepmaZhWakhJcyQo8KJWJknLvjatAKSdJZMZ+4UUMXIQxwO1E 93PHQm2qEyxmnMBae2NN1hYyz/91uOqE7i4zwp4ZnyF5jub/RZZETWZXMVr7jmpr0vi+ JlmzfAOpb49wluFSwjvD7/C/VV2s1ngMgTudB1MYodREKFGnIL8O7QK7GW0ygr4Qpdvn aKUw== 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=GmTz13SaF5QA5tI3kF6niArbxNcTvsMZc/5y93yP4pU=; b=zZEJtkx7KujaXO+H1dwXNCq6dIwRkEYWG0CG8fKUpls6jlVEvHfLbDy0n+94M6+7rI /E0q6kfm7Pk7SaSQa76+shB6UteMgA9O+Wj82WTG9aARQxEmi6ZnbSs1XPdfDeaLGN6h NvAcjqTTFBiMGgU9gcVkEXedadMnhxLIQs7HcU3fsAGkxDS6LfZFw597zqbFXAaZ8kNv ug2uaho7oFfHo1YquNJNbwsTGiPCEtKXJxOk8zMuBrUudazmcXfSH4UoFzingsN8u784 KnMBaISDajPX+WuXSN5+JmhYx/wwucz7WXdY5lerWfMnOFUMp01khkjdF8M6DLV/nIyM au0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=guy91AfP; 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 r18-20020a170906551200b008b7eed5fa18si13022343ejp.986.2023.03.07.09.01.16; Tue, 07 Mar 2023 09:01:50 -0800 (PST) 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=guy91AfP; 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 S229835AbjCGQ66 (ORCPT + 99 others); Tue, 7 Mar 2023 11:58:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbjCGQ6F (ORCPT ); Tue, 7 Mar 2023 11:58:05 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E002F900A5; Tue, 7 Mar 2023 08:54:28 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 2BD08C000F; Tue, 7 Mar 2023 16:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208067; 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=GmTz13SaF5QA5tI3kF6niArbxNcTvsMZc/5y93yP4pU=; b=guy91AfPPHcEdsQm5speMhqIIjA3cVdkn/sunDG4mZh70pke94GGIcreq5jYCcNQMuog7v ymVqv2XSgLeE2e3sCoohDJ6fJASQA0i9GYbU2r4lbR6X0/4SoSpzBhSh0iJUhv7c/pMxpW eblBWFo2qHb9F3ioEDoAgt902vlPXIWwc37cA7i4L89Cj/PFR4laicB2qyih2X3ZK1YUC+ BMyPH2+HIZSTZBPkAm1S4J5rk0rEOp5nDiVZGgeQTOUOHyVA7ov3lMcKPXsFPQi8+OGBQZ Yy/tSl0gVRzhpa/ibBPHvvPKWl23k3THWbx5h3YyLDg4FwWEmdDnt90r+GdSaA== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Heikki Krogerus Subject: [PATCH v2 06/21] usb: ulpi: Use of_request_module() Date: Tue, 7 Mar 2023 17:53:44 +0100 Message-Id: <20230307165359.225361-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729166629106410?= X-GMAIL-MSGID: =?utf-8?q?1759729166629106410?= There is a new helper supposed to replace of_device_request_module(), called of_request_module(). They are both strictly equivalent, besides the fact the latter receives a "struct device_node" directly. Use it. Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Signed-off-by: Miquel Raynal Acked-by: Rob Herring --- drivers/usb/common/ulpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c index 60e8174686a1..6a2b69642e83 100644 --- a/drivers/usb/common/ulpi.c +++ b/drivers/usb/common/ulpi.c @@ -229,7 +229,7 @@ static int ulpi_read_id(struct ulpi *ulpi) request_module("ulpi:v%04xp%04x", ulpi->id.vendor, ulpi->id.product); return 0; err: - of_device_request_module(&ulpi->dev); + of_request_module(ulpi->dev.of_node); return 0; } From patchwork Tue Mar 7 16:53:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65730 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543203wrd; Tue, 7 Mar 2023 09:02:44 -0800 (PST) X-Google-Smtp-Source: AK7set/rRipZYGvcEK54DX2bqwQENRskv15Moa6ZyHon1ieDKJbf0paukzCnuoAAeEHPA507aJ+q X-Received: by 2002:a50:ef19:0:b0:4d2:785f:d4a9 with SMTP id m25-20020a50ef19000000b004d2785fd4a9mr12064188eds.42.1678208564745; Tue, 07 Mar 2023 09:02:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208564; cv=none; d=google.com; s=arc-20160816; b=f/x5tp0zDPR0Dz1eD0MobDvKX7Sugne/BICZx3rKOcr+S/1Zi2usASk9X+XUHLjDfb DI7j3R+7ZFIcqlKAF1DuPXAM86dMzqpM2FisS4IoNijKnCl9bizlBMBYaVV+5FNYzpJU gJ6eG9PgZbFgAA4J9OZPK09/Tf7DuhP9Q3DAjGj5gYs6+rzQZRy4FtPJCHvvC2InFSkj Qu2SIx/Sr2c/XFDOGRqv0uWyaLm03l+Ot+5yav+7Dn1RjpR2SmeWJyiz0+S9uzI2986a V1/Br10ufzMv3Go6STuW+GXKvA1TX/bK2LQ7/6AZvVhWej7+PPkK3/4HQ3ZCynjnzR5g Im8g== 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=CRuE9PZJiPz9C7EOf+r9GXYwrEDm26qK5kWdG2+8fH0=; b=S+Isec0CCH7+BocCXhJ6vQFRuE4SDVyX9sZ25AQM41fHubS8mQfUqn9nSzrm4POead Lv3drDle1SHVU7Zbpg8OotRICbxCTfmZlhkZEkQzHAab2O1HQqNiwiepyt3iUu4Q0xnE Djx06CjGb8ATaK2zUx/CmKNRX1Lk/HxeFjHF2ie2KUkA4vieZfuJyJ41M9qfZK0LXPWd qxU+oUb6Ons6bcsNpsisEmZBjn/rhNylRS2dseYoXuEPjKi63WtnwEi2BBbh8p3jbRN+ KAJMZbnjGnIk33NvPrE9sixF7dL8BhE5IsDhxfOMzDARZqYXUI+0ShTzrTS7mExLf6zi ASng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YKylPxBH; 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 x10-20020a170906710a00b008dcebb5a105si9090950ejj.638.2023.03.07.09.02.19; Tue, 07 Mar 2023 09:02:44 -0800 (PST) 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=YKylPxBH; 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 S231279AbjCGQ7G (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbjCGQ6H (ORCPT ); Tue, 7 Mar 2023 11:58:07 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7720D90B58; Tue, 7 Mar 2023 08:54:30 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id DD194C0004; Tue, 7 Mar 2023 16:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208069; 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=CRuE9PZJiPz9C7EOf+r9GXYwrEDm26qK5kWdG2+8fH0=; b=YKylPxBHewvat29H7KiU18pRcwwvmatUyI/Z7li4zy9cZLuQtYNzjt0pIXdK0lTl+nHxyR +HfcYx9t96EZ7tfy9h3/Ygn8SjJMRvHs2NtQPFOho4VVjj5NkqsNpOvbA5dZAwRUGH27C6 NbA+L+4EChs3unJiDxP8keLuA3wkhXVSlR+CspBRQir50Lgpy/qisIripInOdZTo25UgIU xnEDnYuz3XTDEafiDx0OVIWRMPDRUjXtdMv9o19jG2JlgR4GLYlTlJbMlu4OzGDjCmATKM 9jXeZnqLSOEH3Btn/M9RLSvKwm4MPbaGjBpoYLI2B+2Tp8d2ucJJyoHc7SeMKg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 07/21] of: device: Kill of_device_request_module() Date: Tue, 7 Mar 2023 17:53:45 +0100 Message-Id: <20230307165359.225361-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729223539955359?= X-GMAIL-MSGID: =?utf-8?q?1759729223539955359?= A new helper has been introduced, of_request_module(). Users have been converted, this helper can now be deleted. Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 9 --------- include/linux/of_device.h | 6 ------ 2 files changed, 15 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 4bbb6e6388a9..717392cd416b 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -246,15 +246,6 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -int of_device_request_module(struct device *dev) -{ - if (!dev) - return -ENODEV; - - return of_request_module(dev->of_node); -} -EXPORT_SYMBOL_GPL(of_device_request_module); - /** * of_device_modalias - Fill buffer with newline terminated modalias string * @dev: Calling device diff --git a/include/linux/of_device.h b/include/linux/of_device.h index ab7d557d541d..40c6c8d5299e 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -33,7 +33,6 @@ extern void of_device_unregister(struct platform_device *ofdev); extern const void *of_device_get_match_data(const struct device *dev); extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len); -extern int of_device_request_module(struct device *dev); extern void of_device_uevent(const struct device *dev, struct kobj_uevent_env *env); extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env); @@ -78,11 +77,6 @@ static inline int of_device_modalias(struct device *dev, return -ENODEV; } -static inline int of_device_request_module(struct device *dev) -{ - return -ENODEV; -} - static inline int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) { From patchwork Tue Mar 7 16:53:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65723 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542778wrd; Tue, 7 Mar 2023 09:02:11 -0800 (PST) X-Google-Smtp-Source: AK7set8yplY5fxpQwqwap5wNmUyDiim8RMBMgBFy/nUgCZcP53oFF1kES2CUaoFmGqe0wl25qCcQ X-Received: by 2002:a05:6402:70e:b0:4af:f15b:f6cd with SMTP id w14-20020a056402070e00b004aff15bf6cdmr15186196edx.17.1678208530841; Tue, 07 Mar 2023 09:02:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208530; cv=none; d=google.com; s=arc-20160816; b=RL/+OjBcIiy6OqlvlAUcsIe4ofHjbJREtKgwyrWqHFQhpA8FIXmyc4RlE2s38/zWGn Cb0xfNXkrLNG1aDDgqv1gWxhUF/zjJst/fZpYJGsFt3rGirZqm7VnjPJ83wbvWPlPrY4 3VW8teHvD/PtQoItZGAMPDGuZQY2saA7cMityLlJC084BVdPsdCfaTIRnpoQQ+gVeCrq QM6ip5gOsmSbofPYfJ5ds5oe1Jibhta2IRTjiI5G/gn19ai5IRJTdooquUN7TgWGeLX2 60zyhR/HhwqGl8xfOlBdyRpv6QBVQno0LWCHv+lBhA5XdjiHNdUJP+blCEUVaVQws26o uDkg== 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=OoHOhM6NI+NHubp6HcRrHMGYMYR9q+lJKQNdRjJEoE4=; b=sBa5xs3PC4KUaBVPuc71ujJa9zfyOMqFw6Ii+1vFVQ/ZJwYJ2mi9sLdmH4x+0GE1I8 lyzdfYRRt26YffkRcl+qop2Sd6eqYG/4UwzVoT+HNeDMyP9WTZqZd5ViI7g5mnVkVHDW aOubcAanZWl8FUOrazPHEvXFAmhvsaeWp/58IqXv6ldA4LuteBEvo4tUdwxwgugDLnGA 3xffbTsQ4WwmYlTviZngZC+jHUnP3oPZZqJ8ivoFfJFk5s2W44zFJB+3jEx23jEQLqfo VjVowC5xfG47UggITQVeZj+N8x2ia4hGqgfOqu5fGhkp++++KjxvaB8jwyJCwbx0rD/5 FsNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OiaNIHUu; 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 rp17-20020a170906d97100b008eb27de200esi11390700ejb.278.2023.03.07.09.01.38; Tue, 07 Mar 2023 09:02:10 -0800 (PST) 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=OiaNIHUu; 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 S230261AbjCGQ7L (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjCGQ6H (ORCPT ); Tue, 7 Mar 2023 11:58:07 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6545B90B74; Tue, 7 Mar 2023 08:54:34 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 729ABC000C; Tue, 7 Mar 2023 16:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208071; 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=OoHOhM6NI+NHubp6HcRrHMGYMYR9q+lJKQNdRjJEoE4=; b=OiaNIHUuJ+haJMCU00qbEjkxYKRE676GoY2H97J7SpnpDxUASx3Eht3mUJHYADpS6ZpWR9 u5lExuMHRfU2pdosksYGOc/9OxXwVwApKJBIrgkNu0tUkgaXyORmwnoVDICdeOsZYiNHhw +cQLX3GcEvUIjrbXbBFe1Lgsd0o/hrbT9hCuT8zI7cmckzDWrW0bMkc4bgZoJvHwCFQZ9M E08lTdO9jYohFpARsKsK2CHt2fw4LmTwm4pK1OQWr9yP+GvQcbFM26EUjGqic/JCnQ/SD4 HpuMaaC9EWteZMmPkXR1Rx8PEue9LKNZRH0NaSYSYWzafOZFcl7Vr0+JlthGJw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Colin Ian King , Miquel Raynal Subject: [PATCH v2 08/21] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Date: Tue, 7 Mar 2023 17:53:46 +0100 Message-Id: <20230307165359.225361-9-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729188468101008?= X-GMAIL-MSGID: =?utf-8?q?1759729188468101008?= From: Colin Ian King There is a spelling mistake in platforn-name. Fix it. Signed-off-by: Colin Ian King Signed-off-by: Miquel Raynal Acked-by: Krzysztof Kozlowski --- .../devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml index 5a0e7671aa3f..714a6538cc7c 100644 --- a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml +++ b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml @@ -61,7 +61,7 @@ properties: type: object additionalProperties: false - platforn-name: + platform-name: type: object additionalProperties: false From patchwork Tue Mar 7 16:53:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65743 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2551779wrd; Tue, 7 Mar 2023 09:16:21 -0800 (PST) X-Google-Smtp-Source: AK7set9NHwBqw1riI8jG4B5mEREyrEdC42hhG3mFYBIdUB4ph6z3Nci7eryenam/kSzJLK/k+B/x X-Received: by 2002:a62:38c3:0:b0:5a9:b7e3:2ed1 with SMTP id f186-20020a6238c3000000b005a9b7e32ed1mr12645656pfa.18.1678209381671; Tue, 07 Mar 2023 09:16:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678209381; cv=none; d=google.com; s=arc-20160816; b=f30xwbzGJiOOkyJg+R+9pOLdPZfa/kqW8f0sohiDfcHyON+LK9McJoa/aYuS58KceO 9P+yHuCG40Qryydh7kw6EpoU3tjyAJmAYLfmf2lGy3hZV6LktpTkWZHyJmFu3KbMVBEH nIXbVBzjxeYWxJn1mbCuTNKc2XLxBvJxK3u0dVKptYwG1xUjxD6edEx46n8sHZitgrFh x2RMSPCvkxMFVYfrz0l2spyCBnRmfZkvczi+x/AHUMtMHlf/f5c8H+2x9cXxrVmUOnev i/lZASgrv+bHZjO6gBx1WjhZPlSQJouCjOdUMjQ0cf8W8eRVh28j4lugU0errxochSz9 A9XA== 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=dgBBTfpHgnXZ4Nqwu5rs0ftqLmummhA9TCyJqUGHyhw=; b=LXz0tLyU6D0UplHvOTJx4TAduPQbFR8q2bG4KNamq9HoABcEdhssD1pqJAC6g9sAqt JSl0bgEzIP2twmj6ajpicDYaUUsbTo2QMzjCPMi1KQXA7gxsZcz4nycZkFiqWJmJz8rq lpf1vi55P6QLYdF2IrFAzowjikP89hlxFFK+KHTjgcRb7l7IdV99+dgwGCqlPphKCELN IunLKxfFsmoVeIFc5Ixq9Go6vmOQRZX4h5eVziKhYxKfWLq1sQ/KwC3PPUSrjkAdyF0Z BUwccRMvHpgmOx+SwpBDjv4XcwJ8KjSFk4Qdxwt3BkKDgPHuQMyNREJPMFnGE3l9Un70 UO8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=O8KN2Fyp; 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 g67-20020a636b46000000b005072bddb74csi8861868pgc.846.2023.03.07.09.16.08; Tue, 07 Mar 2023 09:16:21 -0800 (PST) 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=O8KN2Fyp; 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 S230457AbjCGQ7D (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbjCGQ6H (ORCPT ); Tue, 7 Mar 2023 11:58:07 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37EAE94395; Tue, 7 Mar 2023 08:54:34 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 64544C0007; Tue, 7 Mar 2023 16:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208073; 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=dgBBTfpHgnXZ4Nqwu5rs0ftqLmummhA9TCyJqUGHyhw=; b=O8KN2Fypv/egq62SHo1ylWNtpQK89k9X99FpeTrpTrm4ZAYHAKUjW8Ku3Re/82Y7Do4Jy1 OG5pN0UbcKeLfiAMwi/bNb4sH5B32/Gqe5G7sJn60qfBP8Qw/n7SMd4JdE7XBTpC2uwhG7 uEBwusKQYHz/klYvSXJv4MlAHBlLGAIJCtdGorxvIBSF8IPSBfe9NKYHyYH8Ijoriu3HoU kxyHKKBqk1kjJ76HTZF1+i1jIMdx76SlWn01H1w6sf30XqnN9mi2IbzcKegKZEqt+x1hyi I6hajoZtMQDnXw++uRO5xg0eag0ekgjKpLNNsli299UXrALFlKRFOu0kG56dkg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Alexander Stein , Miquel Raynal Subject: [PATCH v2 09/21] nvmem: core: return -ENOENT if nvmem cell is not found Date: Tue, 7 Mar 2023 17:53:47 +0100 Message-Id: <20230307165359.225361-10-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759730080456864656?= X-GMAIL-MSGID: =?utf-8?q?1759730080456864656?= From: Michael Walle Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't found. Particularly, if of_property_match_string() returned -EINVAL, that return code was passed as the index to of_parse_phandle(), which then detected it as invalid and returned NULL. That led to an return code of -ENOENT. With the new code, the negative index will lead to an -EINVAL of of_parse_phandle_with_optional_args() which pass straight to the caller and break those who expect an -ENOENT. Fix it by always returning -ENOENT. Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell") Reported-by: Alexander Stein Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 174ef3574e07..22024b830788 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1231,7 +1231,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) "#nvmem-cell-cells", index, &cell_spec); if (ret) - return ERR_PTR(ret); + return ERR_PTR(-ENOENT); if (cell_spec.args_count > 1) return ERR_PTR(-EINVAL); From patchwork Tue Mar 7 16:53:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2542859wrd; Tue, 7 Mar 2023 09:02:18 -0800 (PST) X-Google-Smtp-Source: AK7set+ngjESKXWoDwWivfOOlh5pSvY04JWi6UlDAzNHOxz4o6tQuuelaMthBS9NV5XBsEfx0X84 X-Received: by 2002:a17:906:7948:b0:8b2:37b5:cc4 with SMTP id l8-20020a170906794800b008b237b50cc4mr22780624ejo.7.1678208538652; Tue, 07 Mar 2023 09:02:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208538; cv=none; d=google.com; s=arc-20160816; b=Oai1+zJ0KpaGtKErBqwPekXiefpsf7ZUzMQiQryJy0eLEq2MVRTtobxRCwLil6qoyV EtLAoJ8yRSMnNNB4Stwt/GXBmxelEPxHMHhysFNvf/mmv0gVKbuuHyunUScpVtQPOTO8 YvZxKVqWkXs0h1lRuHjJql5hHf2hFuwQIGzqnjd5rbFgLUtijmSLhPqBPMidnfmH1Hpm WAaK5NPNeIrdxYWWMumxC/vdD3OdeRRyqsOXUmq+3Q36BjEu7qU+2vonT+nUDVgYHw6o cBRysU1VFBZLRjfMdfxwqs73YUUiEhfroYYk7raNghEcohD3ZZX2dcv+L0oe5LfphVjC eziw== 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=hVQeBtKQXrRO5C0cHH9lHvut6ra7Sd5DplTQYKV162c=; b=knl62/2v7tIhAKTdtwewhAFCT9ZNlgjniIZUhR/iiJOJF59n5kBsmt5wCIyiXRhqXO fvp+Zj3Eabf3cUbC4XjOzET6ymyMbknxdTkpSDGFBv4j6iPGVMLExpJQdeuMdkfIPJYb wFp53TRR+zyHnvFTMOmkM4YucCdiE3QxKnH2NSRtxy90s+7U013qAwsmsZG4dFOB3gIJ EnEjwM5KZDDJSxfqrlajovnBLq/czju28lescG9kO0xhX4MfWRneV4vHQI3aj/0xixue qDNu1/5W1OytHMIFrcpG5NDCKlSE4qLTuhSCOjaExWLfTZyzVslz9ActpbCy2+ubm/vB 1ZPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=nHDxeF6I; 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 k16-20020aa7d8d0000000b004af6a805793si1779248eds.601.2023.03.07.09.01.52; Tue, 07 Mar 2023 09:02:18 -0800 (PST) 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=nHDxeF6I; 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 S229636AbjCGQ7T (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbjCGQ6I (ORCPT ); Tue, 7 Mar 2023 11:58:08 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D285393113; Tue, 7 Mar 2023 08:54:35 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 37F52C0003; Tue, 7 Mar 2023 16:54:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208074; 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=hVQeBtKQXrRO5C0cHH9lHvut6ra7Sd5DplTQYKV162c=; b=nHDxeF6IE8zHfkDGf0IkcoLtaGxUycfiERmJxhmrlh0ri0LFW4gGMTWo+QUDQKj+ggYb0q Nn5HYYGvwxy8c0Hqu20Q8VpzlNhb7fFqmRMmkcqqFenU1qyd6mUUOsOFM1LSlC3a8ZqtGY tGy98BsBeDw9a3yHUOV3FB5iY6tIUvvu4I/jcbOlaG1TGQiDvdsNj2EwgQWPwEBi2P3/p8 mYnEASS+SV1hQM6GTwhb5r9muoPK+wlZkuto89MNGnRcAFXzR8wcmM3vN/xxEq5oeNWg5z XBUHNBeWtG0/w/yDwKyJkCgdrZriDHOVx1t0QCAMNWvVlONLgArQy7uoYjtk0A== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 10/21] nvmem: core: introduce NVMEM layouts Date: Tue, 7 Mar 2023 17:53:48 +0100 Message-Id: <20230307165359.225361-11-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729196795612888?= X-GMAIL-MSGID: =?utf-8?q?1759729196795612888?= From: Michael Walle NVMEM layouts are used to generate NVMEM cells during runtime. Think of an EEPROM with a well-defined conent. For now, the content can be described by a device tree or a board file. But this only works if the offsets and lengths are static and don't change. One could also argue that putting the layout of the EEPROM in the device tree is the wrong place. Instead, the device tree should just have a specific compatible string. Right now there are two use cases: (1) The NVMEM cell needs special processing. E.g. if it only specifies a base MAC address offset and you need to add an offset, or it needs to parse a MAC from ASCII format or some proprietary format. (Post processing of cells is added in a later commit). (2) u-boot environment parsing. The cells don't have a particular offset but it needs parsing the content to determine the offsets and length. Co-developed-by: Miquel Raynal Signed-off-by: Miquel Raynal Signed-off-by: Michael Walle --- Documentation/driver-api/nvmem.rst | 15 ++++ drivers/nvmem/Kconfig | 4 + drivers/nvmem/Makefile | 1 + drivers/nvmem/core.c | 120 +++++++++++++++++++++++++++++ drivers/nvmem/layouts/Kconfig | 5 ++ drivers/nvmem/layouts/Makefile | 4 + include/linux/nvmem-consumer.h | 7 ++ include/linux/nvmem-provider.h | 51 ++++++++++++ 8 files changed, 207 insertions(+) create mode 100644 drivers/nvmem/layouts/Kconfig create mode 100644 drivers/nvmem/layouts/Makefile diff --git a/Documentation/driver-api/nvmem.rst b/Documentation/driver-api/nvmem.rst index e3366322d46c..de221e91c8e3 100644 --- a/Documentation/driver-api/nvmem.rst +++ b/Documentation/driver-api/nvmem.rst @@ -185,3 +185,18 @@ ex:: ===================== See Documentation/devicetree/bindings/nvmem/nvmem.txt + +8. NVMEM layouts +================ + +NVMEM layouts are yet another mechanism to create cells. With the device +tree binding it is possible to specify simple cells by using an offset +and a length. Sometimes, the cells doesn't have a static offset, but +the content is still well defined, e.g. tag-length-values. In this case, +the NVMEM device content has to be first parsed and the cells need to +be added accordingly. Layouts let you read the content of the NVMEM device +and let you add cells dynamically. + +Another use case for layouts is the post processing of cells. With layouts, +it is possible to associate a custom post processing hook to a cell. It +even possible to add this hook to cells not created by the layout itself. diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 6dec38805041..ae2c5257ed97 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -21,6 +21,10 @@ config NVMEM_SYSFS This interface is mostly used by userspace applications to read/write directly into nvmem. +# Layouts + +source "drivers/nvmem/layouts/Kconfig" + # Devices config NVMEM_APPLE_EFUSES diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 6a1efffa88f0..f82431ec8aef 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_NVMEM) += nvmem_core.o nvmem_core-y := core.o +obj-y += layouts/ # Devices obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 22024b830788..b9be1faeb7be 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -40,6 +40,7 @@ struct nvmem_device { nvmem_reg_write_t reg_write; nvmem_cell_post_process_t cell_post_process; struct gpio_desc *wp_gpio; + struct nvmem_layout *layout; void *priv; }; @@ -74,6 +75,9 @@ static LIST_HEAD(nvmem_lookup_list); static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); +static DEFINE_SPINLOCK(nvmem_layout_lock); +static LIST_HEAD(nvmem_layouts); + static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, void *val, size_t bytes) { @@ -728,6 +732,101 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) return 0; } +int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner) +{ + layout->owner = owner; + + spin_lock(&nvmem_layout_lock); + list_add(&layout->node, &nvmem_layouts); + spin_unlock(&nvmem_layout_lock); + + return 0; +} +EXPORT_SYMBOL_GPL(__nvmem_layout_register); + +void nvmem_layout_unregister(struct nvmem_layout *layout) +{ + spin_lock(&nvmem_layout_lock); + list_del(&layout->node); + spin_unlock(&nvmem_layout_lock); +} +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 nvmem_layout *l, *layout = NULL; + + layout_np = of_get_child_by_name(np, "nvmem-layout"); + if (!layout_np) + return NULL; + + spin_lock(&nvmem_layout_lock); + + list_for_each_entry(l, &nvmem_layouts, node) { + if (of_match_node(l->of_match_table, layout_np)) { + if (try_module_get(l->owner)) + layout = l; + + break; + } + } + + spin_unlock(&nvmem_layout_lock); + of_node_put(layout_np); + + return layout; +} + +static void nvmem_layout_put(struct nvmem_layout *layout) +{ + if (layout) + module_put(layout->owner); +} + +static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) +{ + struct nvmem_layout *layout = nvmem->layout; + int ret; + + if (layout && layout->add_cells) { + ret = layout->add_cells(&nvmem->dev, nvmem, layout); + if (ret) + return ret; + } + + return 0; +} + +#if IS_ENABLED(CONFIG_OF) +/** + * of_nvmem_layout_get_container() - Get OF node to layout container. + * + * @nvmem: nvmem device. + * + * Return: a node pointer with refcount incremented or NULL if no + * container exists. Use of_node_put() on it when done. + */ +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) +{ + return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); +} +EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); +#endif + +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + struct device_node __maybe_unused *layout_np; + const struct of_device_id *match; + + layout_np = of_nvmem_layout_get_container(nvmem); + match = of_match_node(layout->of_match_table, layout_np); + + return match ? match->data : NULL; +} +EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data); + /** * nvmem_register() - Register a nvmem device for given nvmem_config. * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem @@ -834,6 +933,12 @@ 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 (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) @@ -854,12 +959,17 @@ 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; + 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); if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: @@ -881,6 +991,7 @@ static void nvmem_device_release(struct kref *kref) device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); nvmem_device_remove_all_cells(nvmem); + nvmem_layout_put(nvmem->layout); device_unregister(&nvmem->dev); } @@ -1246,6 +1357,15 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) return ERR_PTR(-EINVAL); } + /* nvmem layouts produce cells within the nvmem-layout container */ + if (of_node_name_eq(nvmem_np, "nvmem-layout")) { + nvmem_np = of_get_next_parent(nvmem_np); + if (!nvmem_np) { + of_node_put(cell_np); + return ERR_PTR(-EINVAL); + } + } + nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); of_node_put(nvmem_np); if (IS_ERR(nvmem)) { diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig new file mode 100644 index 000000000000..9ad3911d1605 --- /dev/null +++ b/drivers/nvmem/layouts/Kconfig @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "Layout Types" + +endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile new file mode 100644 index 000000000000..6fdb3c60a4fa --- /dev/null +++ b/drivers/nvmem/layouts/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for nvmem layouts. +# diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 1f62f7ba71ca..fa030d93b768 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -239,6 +239,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id); struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *name); +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem); #else static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) @@ -251,6 +252,12 @@ static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, { return ERR_PTR(-EOPNOTSUPP); } + +static inline struct device_node * +of_nvmem_layout_get_container(struct nvmem_device *nvmem) +{ + return ERR_PTR(-EOPNOTSUPP); +} #endif /* CONFIG_NVMEM && CONFIG_OF */ #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 0262b86194eb..535c5f9f3309 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -88,6 +88,7 @@ struct nvmem_cell_info { * @stride: Minimum read/write access stride. * @priv: User context passed to read/write callbacks. * @ignore_wp: Write Protect pin is managed by the provider. + * @layout: Fixed layout associated with this nvmem device. * * Note: A default "nvmem" name will be assigned to the device if * no name is specified in its configuration. In such case "" is @@ -109,6 +110,7 @@ struct nvmem_config { bool read_only; bool root_only; bool ignore_wp; + struct nvmem_layout *layout; struct device_node *of_node; bool no_of_node; nvmem_reg_read_t reg_read; @@ -142,6 +144,33 @@ struct nvmem_cell_table { struct list_head node; }; +/** + * struct nvmem_layout - NVMEM layout definitions + * + * @name: Layout name. + * @of_match_table: Open firmware match table. + * @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(). + * @owner: Pointer to struct module. + * @node: List node. + * + * A nvmem device can hold a well defined structure which can just be + * evaluated during runtime. For example a TLV list, or a list of "name=val" + * pairs. A nvmem layout can parse the nvmem device and add appropriate + * cells. + */ +struct nvmem_layout { + const char *name; + const struct of_device_id *of_match_table; + int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout); + + /* private */ + struct module *owner; + struct list_head node; +}; + #if IS_ENABLED(CONFIG_NVMEM) struct nvmem_device *nvmem_register(const struct nvmem_config *cfg); @@ -156,6 +185,14 @@ void nvmem_del_cell_table(struct nvmem_cell_table *table); int nvmem_add_one_cell(struct nvmem_device *nvmem, const struct nvmem_cell_info *info); +int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner); +#define nvmem_layout_register(layout) \ + __nvmem_layout_register(layout, THIS_MODULE) +void nvmem_layout_unregister(struct nvmem_layout *layout); + +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout); + #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) @@ -179,5 +216,19 @@ static inline int nvmem_add_one_cell(struct nvmem_device *nvmem, return -EOPNOTSUPP; } +static inline int nvmem_layout_register(struct nvmem_layout *layout) +{ + return -EOPNOTSUPP; +} + +static inline void nvmem_layout_unregister(struct nvmem_layout *layout) {} + +static inline const void * +nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + return NULL; +} + #endif /* CONFIG_NVMEM */ #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ From patchwork Tue Mar 7 16:53:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65728 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543037wrd; Tue, 7 Mar 2023 09:02:32 -0800 (PST) X-Google-Smtp-Source: AK7set+1uC1l799zIMVpndR0oJs1sf5Uj9ZtkD/PciPuNjLZ9pz22mnzLavD8oQ+gjaxFx96HsWW X-Received: by 2002:a50:ee18:0:b0:4a0:e31a:434 with SMTP id g24-20020a50ee18000000b004a0e31a0434mr13370921eds.27.1678208552746; Tue, 07 Mar 2023 09:02:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208552; cv=none; d=google.com; s=arc-20160816; b=cWIpc4fmBzRJvaG++RIvpq9GpHEHol2rE/ighDumfF+c1UOmOrRxNcWoag93DsAGrz YWOXr65qLlSlhVJ+ofTtey/RBIlVIRDQUizZSdrrycSfadQxIOB4F1qv9b9nxLqGwQh7 frsw4FKktFnxV7ysNkAs1rlEiCoDUOiQ5iIYq855vuPoxiLTiay5JlrbHJShC7xGMoCJ NQxKF5QlVNQe4xEieoFusV9IvwOmm1km+VkpxztFnm1uXDGCtpWUuOSZQhjiXAsKiN/t CdPEaRCLbhh0iFVJpcOfsuuYaRd962u0vVBG07qkA2eY/wqSPgtpCSwi4NcRB3rDJVG3 iyPA== 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=7KeyBQUfcV1ky8pfB8UN0PcucnmwJo4XrlM30Q7JJvc=; b=UcvlkkB0Mj2diZnOUONiYHVBCyzrEpZtYbWFGMvWB3vTDI8qW+N04Sytw4PNkJgSb2 Vi+fpWU0Gyqy0iqJRbRP6ZHxxyTMHIp2uVPei8OuL4PjZkOp3N21DojkHa6/oETqt4U1 69ALa3hQbaKMJTccyEu3zYpBiqXfYy5P6TEDPy2T71sq5QPmGfSn9tupbJlvtWpBGhLj +1hI9pc349vV/2tecVTb3+LFVLZz/iOFT4V0wBKMUKRaHVsdy21AtC8z+oQy6uBDYjHf 7jsdI1mcpHJScj/XQB5SFSk+KM89TYUUAW8AZhPzbL9m7qzTr3dReQnPpdykYLvNXM8i 7JQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YH8LjfQK; 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 i2-20020aa7c702000000b004acc6c7a631si14723135edq.179.2023.03.07.09.02.06; Tue, 07 Mar 2023 09:02:32 -0800 (PST) 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=YH8LjfQK; 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 S230355AbjCGQ7j (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230447AbjCGQ6J (ORCPT ); Tue, 7 Mar 2023 11:58:09 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F141943A4; Tue, 7 Mar 2023 08:54:38 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id C58F9C0005; Tue, 7 Mar 2023 16:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208076; 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=7KeyBQUfcV1ky8pfB8UN0PcucnmwJo4XrlM30Q7JJvc=; b=YH8LjfQKOD4APKo2dXxpQh5JpBZKiHnVtOecfGa8P53v+ZmDgbTRI0chH0QkBhnsgtDA28 g0KQh4E43YVWufPcsgOI3zZowESs1t/LrjUhW9fqYY+rnTthXoaqqvRMbOAHBK5qwpfKzr dLb9otb88omqLU97X51cyPKVfPf5PzcUHiCnQilM7fiRmTpHYpHCHqWTznihvFhend7tLa mWEDrfzwrBGb+jsbqn89WUlMt+20hzq04m0hb3lthlmxHFKHSfNvFQcV3CXLPSaP/kGJU9 mPf05zbQLyWxf8/B+d7ULAcwjdAnRZzGmHwXgGVwHzeM0WkXqMqaBDsKCvl+EQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 11/21] nvmem: core: handle the absence of expected layouts Date: Tue, 7 Mar 2023 17:53:49 +0100 Message-Id: <20230307165359.225361-12-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729211421559130?= X-GMAIL-MSGID: =?utf-8?q?1759729211421559130?= Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout is not available. This condition cannot be triggered today as nvmem layout drivers are initialed as part of an early init call, but soon these drivers will be converted into modules and be initialized with a standard priority, so the unavailability of the drivers might become a reality that must be taken care of. Let's anticipate this by telling the caller the layout might not yet be available. A probe deferral is requested in this case. Please note this does not affect any nvmem device not using layouts, because an early check against the "nvmem-layout" container presence will return NULL in this case. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b9be1faeb7be..51fd792b8d70 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -755,7 +755,7 @@ 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 nvmem_layout *l, *layout = NULL; + struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); layout_np = of_get_child_by_name(np, "nvmem-layout"); if (!layout_np) @@ -938,6 +938,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) * pointer will be NULL and nvmem_layout_put() will be a noop. */ nvmem->layout = 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); @@ -970,6 +977,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); nvmem_layout_put(nvmem->layout); +err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: From patchwork Tue Mar 7 16:53:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543188wrd; Tue, 7 Mar 2023 09:02:43 -0800 (PST) X-Google-Smtp-Source: AK7set/dPrs/9VLnP5yD9gN3/SeSfFmV4sUCdq4bBwFC1gVpCSyu5kAHmp4VzmxReI3UOLIPc8QU X-Received: by 2002:a05:6402:1512:b0:4c2:6b68:c126 with SMTP id f18-20020a056402151200b004c26b68c126mr3673617edw.8.1678208563833; Tue, 07 Mar 2023 09:02:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208563; cv=none; d=google.com; s=arc-20160816; b=tsJQzhTxhUDUJ1D6pmvY1jEtX3PFxl+Mzc4MXGCTY8Mnx0vuSsVPoy0PHR9X0gvckt c1M4sCHnegaaFDkeE/+E4rS2hH8u7olxngPVdgQE93B8glkHc8vkbeEhS4AyDUfBHMfH YJuR35tXw5XMimLO+vCq3YooCNySRgN2yv5EIckqIw0slr3u6TH7Crn3xbksEDdTgyev oK46uxOpMp2Fh6B+jcFYd0flzd1LpRiCyKYCkSRFihlAq26LXXNt7XJJrIARiTKxGo42 v1zkpF8Zv41Fivy5qGFW6OreBx+o4PqgI/6X4flzHeVAytQbnxgpDrbBJoC0NfFFaD0+ oCVQ== 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=kOBXXD4vbju2aL5V1RwDCtfqYKoZS1/2BAnTjzjhigg=; b=zWpDzyCc19lZaExCY4GSthWaQTv6lPLVs1XMkrsEsaLE+JfDdRgGkx0A9F5O51ASQg /DDw2XgvAl2tBsrHMnuKpUVWxs+vtrCH2M5Usqq5RUti7Cx4R1VXDznEqzzkx876epDx CJcV65xE2CBdSg4SfbiOQQ/OYVWbaLs6zmNEP8Oc0jy8Cy/Ydh3hlpkRcoCCDuMQEoA0 u5IPRpAUXejBjLQ7eoCClnbj7XolmZHN4Xi36VgTy6eNEuY6CZChZBk9Kh9iB59Yw1me NJU7MmOO0TtsMtzZ7+8SgYUEG3Gc32bidlbw1912Xt8KxckE8DIu22J5hk/OC9traHDb fP9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XmvOkhJe; 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 e1-20020a50fb81000000b004af6a815065si1833556edq.592.2023.03.07.09.02.17; Tue, 07 Mar 2023 09:02:43 -0800 (PST) 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=XmvOkhJe; 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 S230391AbjCGQ7o (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbjCGQ6K (ORCPT ); Tue, 7 Mar 2023 11:58:10 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5426B90099; Tue, 7 Mar 2023 08:54:46 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 2D87BC000D; Tue, 7 Mar 2023 16:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208085; 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=kOBXXD4vbju2aL5V1RwDCtfqYKoZS1/2BAnTjzjhigg=; b=XmvOkhJe/csozAO8RiC8briNTgzHaFAAeLwzDqCK5gHSaayiyxCSAkjAukIRH1k59bhq/K +S0T3pupqkvWW+nNIBG51gEyZ1XnlGdxOq2oW4sGPQJbn3Sl48GvY7jtAsEBDe27jebiQ4 Ia3We7tWbjefJ4ukYMM7B7+tZGgv6mYd9apYvPCLOyKeBqxCByy3Be5QlXHNucg15MMX0s Anh4WXFdYr4ue087X/eRxrHSHtg7EiLe3loDg9kRjG1ryd3ff4xqkCkKNDgojG5Go4WGhM wa8FHizTxjoWOmLsYgTHU3X3To44xP+GI8cPPPvRZn5a7NbOHm6IkskEUU4sew== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 12/21] nvmem: core: request layout modules loading Date: Tue, 7 Mar 2023 17:53:50 +0100 Message-Id: <20230307165359.225361-13-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729223262225741?= X-GMAIL-MSGID: =?utf-8?q?1759729223262225741?= When a storage device like an eeprom or an mtd device probes, it registers an nvmem device if the nvmem subsystem has been enabled (bool symbol). During nvmem registration, if the device is using layouts to expose dynamic nvmem cells, the core will first try to get a reference over the layout driver callbacks. In practice there is not relationship that can be described between the storage driver and the nvmem layout. So there is no way we can enforce both drivers will be built-in or both will be modules. If the storage device driver is built-in but the layout is built as a module, instead of badly failing with an endless probe deferral loop, lets just make a modprobe call in case the driver was made available in an initramfs with of_device_node_request_module(), and offer a fully functional system to the user. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 51fd792b8d70..9ef7617e2718 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include struct nvmem_device { @@ -761,6 +762,13 @@ static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *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_device_node_request_module(layout_np); + spin_lock(&nvmem_layout_lock); list_for_each_entry(l, &nvmem_layouts, node) { From patchwork Tue Mar 7 16:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543254wrd; Tue, 7 Mar 2023 09:02:48 -0800 (PST) X-Google-Smtp-Source: AK7set+HBJRNFXkQyEYVt3u5RPgD4emk8IADQeeBzF6s/Daw6V7dT0ZOIYfjwpzf9k5hPUeiJCps X-Received: by 2002:a05:6402:14ce:b0:4ac:b528:5727 with SMTP id f14-20020a05640214ce00b004acb5285727mr15805395edx.1.1678208568823; Tue, 07 Mar 2023 09:02:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208568; cv=none; d=google.com; s=arc-20160816; b=TlEmROQiqUVKe8XZXkU9mHwCN3+r61ZexenxRmCDU9yVtTrPPAYeKGsRedwj1ujqPc 0/KUQqVvvI+JFHrObKMiq1UCfhDLxroeKUFtRQ56tJRPTlRExLbpEdLFSYaEQqbiVms+ oQzHzRpJu+v7o1r9manyv71tEmfdlTW+rfHMsG/tP9c4hs0aUyDdSJji+h0Ezg5l7P7H bbsina9snecG3pAz3FWvw1l66nCBkS5PpxxrNwLZfk/qsYcK5M5I2tefCXqjV7namvrS RyVGk4KuTSigPWp2xw0UO562KCIYh0FC0V9FJCr2j14ra+29dKMEoOtWCE8ktqO04rrt at2Q== 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=Qq9KTz3txl7c0YKP2R+SoNEgCca4N7qkHJIQfTnqnB0=; b=wixAtZEfBdkhxmxvcxYq7U+ZhlMsk2l2GpvrkrDwOXxXT6p3egToVoejw7yq4XOVc6 Rzpp5MCdSRZu6ON8j1ZRSXFcYSns4cOz2G/BjzIVJO9J8vF5K+iy5jzcKoc7wJ5llY+d bdY7QsuNGmEDN2zHc9JmH49LQH+GEfh5Zw5yqMW7myYWAJbcOhklA41KDaHYb6AVqeRs JgjqNL+D4zFbWViLafd1JycaeYkPDtj92TO4+xw/YywFYCF6fAURVmN4h28veeLBTYBJ l0hqqbU+uLOO90dU6EaQZxvyfBD9FugOUrPqiRvyezIu4YxEea8PLPlgpoKuxnwGCFSE LsEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BqUwDEmC; 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 b20-20020a05640202d400b004beeaa6bc04si926272edx.97.2023.03.07.09.02.24; Tue, 07 Mar 2023 09:02:48 -0800 (PST) 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=BqUwDEmC; 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 S231341AbjCGQ7y (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbjCGQ6M (ORCPT ); Tue, 7 Mar 2023 11:58:12 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F90C50F97; Tue, 7 Mar 2023 08:54:52 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id DC350C0004; Tue, 7 Mar 2023 16:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208091; 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=Qq9KTz3txl7c0YKP2R+SoNEgCca4N7qkHJIQfTnqnB0=; b=BqUwDEmCOmDbtJOXsu6LWwxV7+sGgWmH/YBwjdJshEM0rTlFvpnS8S1iY4jWLnNQYe1V+1 42tZ7bx9/Q1dQbPdaviE8X5JlLNO07rg9pI3Uu6wePkuqvY1IjG5mdtYbh04szYwbDwLuX 0YQ3sgzbo0/CQBkhBFrU8sNDUvWrl8Pca4CaihjKq8RZ8F79NFZaNH0i9TPl6cpHJszDvU lcw1YkA8pfhUK1xHjZOrzf/ntwIG5L+14B6XQZYsntdaQD73lWZWGmUWjb2zkVdD7cKzXX qdesFpTCycQbUf2Law84DErifUhXUOccjB6sYmIKq2rdvmpV4jknrFsGBEr3rA== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 13/21] nvmem: core: add per-cell post processing Date: Tue, 7 Mar 2023 17:53:51 +0100 Message-Id: <20230307165359.225361-14-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729228072592811?= X-GMAIL-MSGID: =?utf-8?q?1759729228072592811?= From: Michael Walle Instead of relying on the name the consumer is using for the cell, like it is done for the nvmem .cell_post_process configuration parameter, provide a per-cell post processing hook. This can then be populated by the NVMEM provider (or the NVMEM layout) when adding the cell. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 17 +++++++++++++++++ include/linux/nvmem-provider.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 9ef7617e2718..664d48f0dfa7 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -54,6 +54,7 @@ struct nvmem_cell_entry { int bytes; int bit_offset; int nbits; + nvmem_cell_post_process_t read_post_process; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -470,6 +471,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->offset = info->offset; cell->bytes = info->bytes; cell->name = info->name; + cell->read_post_process = info->read_post_process; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1563,6 +1565,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, if (cell->bit_offset || cell->nbits) nvmem_shift_read_buffer_in_place(cell, buf); + if (cell->read_post_process) { + rc = cell->read_post_process(nvmem->priv, id, index, + cell->offset, buf, cell->bytes); + if (rc) + return rc; + } + if (nvmem->cell_post_process) { rc = nvmem->cell_post_process(nvmem->priv, id, index, cell->offset, buf, cell->bytes); @@ -1671,6 +1680,14 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si (cell->bit_offset == 0 && len != cell->bytes)) return -EINVAL; + /* + * Any cells which have a read_post_process hook are read-only because + * we cannot reverse the operation and it might affect other cells, + * too. + */ + if (cell->read_post_process) + return -EINVAL; + if (cell->bit_offset || cell->nbits) { buf = nvmem_cell_prepare_write_buffer(cell, buf, len); if (IS_ERR(buf)) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 535c5f9f3309..3bfc23553a9e 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -54,6 +54,8 @@ struct nvmem_keepout { * @bit_offset: Bit offset if cell is smaller than a byte. * @nbits: Number of bits. * @np: Optional device_node pointer. + * @read_post_process: Callback for optional post processing of cell data + * on reads. */ struct nvmem_cell_info { const char *name; @@ -62,6 +64,7 @@ struct nvmem_cell_info { unsigned int bit_offset; unsigned int nbits; struct device_node *np; + nvmem_cell_post_process_t read_post_process; }; /** From patchwork Tue Mar 7 16:53:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543424wrd; Tue, 7 Mar 2023 09:03:02 -0800 (PST) X-Google-Smtp-Source: AK7set+SxxsGw/4NDHfOduZ97EsHoOm+AfnI3pHx5XsftOI+f/X7635sMBQ6Dh8WDU5dQFrdxYZF X-Received: by 2002:a17:906:730d:b0:8b1:3193:4874 with SMTP id di13-20020a170906730d00b008b131934874mr19206087ejc.46.1678208582688; Tue, 07 Mar 2023 09:03:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208582; cv=none; d=google.com; s=arc-20160816; b=qnT/XBQGcTqdkU0j6fnWApGL8RFNBqUoADPxVi6qHCyoX3nyJIB8FRQR4fltD/ty8E f7hpgIwZLXHccqwsPUksYHsVRAsWyhFwudgYslUYvCnCqzX0VqMflgw4TwwxAV6lRPIT iXs/ppGSb10212YW1twFHr8yAodyWDV2ArX14KQRbC66HPvcfLBu48qRIndUTpKuCcQj v2JtHnN7uluakpoR5ZLDdvlH9UP7Hx1aeIcA1kIu0cQoXmhxPQ811UtQIosfxfrtZGHq Ela3zgkqMsH6relhavQwd9Ds/7wubv3O+5oAtdcsFQ7rb2vp6WvKYTsV04aRT6iCzVyi WrGg== 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=6hNxCYBR5yzRDGBSbfvJ7idoAKl7NjU5wAcCzaXPD2w=; b=L4U5beK9iA6TopXbw5Cr1KFm7B9TOvLPjubUrQA7nzDHc4x1ImTiLOKE24C3/lPRYW KakZUzXY5s4WojuiGdJ4vXectsmKHjecvyq/z5oD7JTdZZvt78Xz1cScVHwMI2Ki/QLE bC/FVpaq9fqUDQmYBLmY63qCKhNyCxpGrH4RDfkZBkehn1+9VPAVszFXexJiNUNmm/9n Tvw0qxoUoKNJVBbAN1FIpBJkE768xMGoCnV8VouW5Z4bFPNZx6YzS+AHUeIyxHHev1bd ZpWSHwdqM/ySbBVVqi+qxnSBrnIHAf4M/5G5w3X4RpgrXpbFulS1Jc5ifnUy5gku0v/F 7njA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=SXd0K+s7; 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 e18-20020a170906c01200b008d4ddc88221si4304861ejz.510.2023.03.07.09.02.38; Tue, 07 Mar 2023 09:03:02 -0800 (PST) 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=SXd0K+s7; 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 S231434AbjCGRAC (ORCPT + 99 others); Tue, 7 Mar 2023 12:00:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230501AbjCGQ6M (ORCPT ); Tue, 7 Mar 2023 11:58:12 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE6C959E0; Tue, 7 Mar 2023 08:54:54 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 49391C0007; Tue, 7 Mar 2023 16:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208093; 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=6hNxCYBR5yzRDGBSbfvJ7idoAKl7NjU5wAcCzaXPD2w=; b=SXd0K+s7oI2QByaA7bb9vJpRXYpl2uydhFjRxV+TmG/Ic38saSyLyA/G8YCRyzs8L8Scek NjRlMTPTf/IeLkL8n6psTRSeR3QNrdWCNXb+pnZZCwY2p2+Yg5BwXvp2Qgpd/l8vD/9sLi 0w/QBkDSAcR6oXrTrdNiIiCpifkfphn8Slu9GCN02HvqIdRIQuT3YGMadwJ+yUvbZAs33I HCdP9bsnuXnxkhcx+N4RaT3Qna0xFb+aa1mckogyeUpMK7XLILmTfkj49OHELeXQP3BbqW /u99Ugi5LgvVeXLtI/l0il/lGuBeYuJ3Wr7bSoBTKQkr2uz76FIqTf0WBLtMvA== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 14/21] nvmem: core: allow to modify a cell before adding it Date: Tue, 7 Mar 2023 17:53:52 +0100 Message-Id: <20230307165359.225361-15-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729243235672754?= X-GMAIL-MSGID: =?utf-8?q?1759729243235672754?= From: Michael Walle Provide a way to modify a cell before it will get added. This is useful to attach a custom post processing hook via a layout. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-provider.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 664d48f0dfa7..82e11b9576ad 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -695,6 +695,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem) static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) { + struct nvmem_layout *layout = nvmem->layout; struct device *dev = &nvmem->dev; struct device_node *child; const __be32 *addr; @@ -724,6 +725,9 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) info.np = of_node_get(child); + if (layout && layout->fixup_cell_info) + layout->fixup_cell_info(nvmem, layout, &info); + ret = nvmem_add_one_cell(nvmem, &info); kfree(info.name); if (ret) { diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 3bfc23553a9e..be81cc88eabc 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -155,6 +155,8 @@ struct nvmem_cell_table { * @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(). + * @fixup_cell_info: Will be called before a cell is added. Can be + * used to modify the nvmem_cell_info. * @owner: Pointer to struct module. * @node: List node. * @@ -168,6 +170,9 @@ struct nvmem_layout { const struct of_device_id *of_match_table; int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, struct nvmem_layout *layout); + void (*fixup_cell_info)(struct nvmem_device *nvmem, + struct nvmem_layout *layout, + struct nvmem_cell_info *cell); /* private */ struct module *owner; From patchwork Tue Mar 7 16:53:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65733 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543943wrd; Tue, 7 Mar 2023 09:03:47 -0800 (PST) X-Google-Smtp-Source: AK7set9XBnKJXGdHfMDNQF1CiEVR/LSgePAMLD7K1xdLIxnOxfpGFhjWUT12QCTMjrV1ce8acuza X-Received: by 2002:aa7:d796:0:b0:4ac:d2bc:4695 with SMTP id s22-20020aa7d796000000b004acd2bc4695mr14583246edq.33.1678208627507; Tue, 07 Mar 2023 09:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208627; cv=none; d=google.com; s=arc-20160816; b=gLQwTyBe1s7IH3J8dpG/Vo2eWhBIjEku1ftGIAS/r4EbhEPVIK/Cz+NlJsPj/KRbYm qjoALYLTHEL95HwiKk3o1FyFxbhBeE8eu44UikQGFpRGndWiagBTKlkKg0dlEwvtFHjZ vD53NE4q1cu+eeZIM83YR4p/O7M7ZaETcvrctkKeHCJnhmpHryMQGKxlSGIPTE9d4s9d NQdQd2QW+px9JDPCfF/ecafKDkMsbdZvLKGXupF8LYPbO5/JbxBhIzVNWxlh1py/aTO/ Cuue37ytUpR8TYUjWxbNdzV1HolbbxT3g3XfcoNKOVxLf7sxJs64qh8tIpmwFvI6Dr1n uMZw== 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=+8KBJRUvcteGrcXB2dPcvKQXMIPPTo96B4W8ORMytWg=; b=V79vKNxfpabwmO6+iAfbT0lAB+Sr9yllPUWO0EY3MmfpG3KIlnzREVh6i7qJBWgAZN Eoko4nzrYUos/q85BiJeXqKQYgiJQKBKiRuxFHgxvaHDunE7mtMaeO6NcIQVgace57CT j7n00ZYSl1bf0/e+BYRZUkK2dgQXkrulpizrd/RhN6R+s7j7DwFbYOnEsAmaMNrXlB8W S7/y6+fZQjjqLfSOgPm9IVjGLd3duibDHqikg3QtOiKzE7VW8gsqA/GOihxf9z2mZ6JY 8neMfP4HC8DsMAvJ+vQCGIR0eNJJje3Oyt4mlmS+xwPSxIsDWE3j3fV3D2hYiwZIscoM NMEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Yr3FZKIm; 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 gu25-20020a170906f29900b008d65603e880si858469ejb.583.2023.03.07.09.03.23; Tue, 07 Mar 2023 09:03:47 -0800 (PST) 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=Yr3FZKIm; 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 S231298AbjCGQ7t (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjCGQ6M (ORCPT ); Tue, 7 Mar 2023 11:58:12 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F95190096; Tue, 7 Mar 2023 08:54:58 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B623EC0009; Tue, 7 Mar 2023 16:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208096; 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=+8KBJRUvcteGrcXB2dPcvKQXMIPPTo96B4W8ORMytWg=; b=Yr3FZKImd9D4HbqsfoBk+mm8YZ/3s9YDFloLhooDu8S0DJb9p7XI3IyDJhfleAo+qg35Bi 8/K6+gW/14Vf/d6aLcW+pC00XS2IKd44eMKPluCRRysIVFfQt54WzmosQ3goHCY8TC0k+Z MFpqlpp1klW8YbDHfdetOf5/r7t+oynKqp+8+VzPOb20UNl/SgrvJWyx6gRphzsJtPCoXZ 4vchA9z9vNyXyviwQjM6R8uuyONisbqDI9ZTFLQIdJxM/2lqSRnVXOJZlOwaUKzTdAhd8a yI41jVNW5w2ay/TGDE/7uKUjjj3tTl5u7+H2GoLS7KZGeKSDSrm17r0XM5qbEQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 15/21] nvmem: imx-ocotp: replace global post processing with layouts Date: Tue, 7 Mar 2023 17:53:53 +0100 Message-Id: <20230307165359.225361-16-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729289630094429?= X-GMAIL-MSGID: =?utf-8?q?1759729289630094429?= From: Michael Walle In preparation of retiring the global post processing hook change this driver to use layouts. The layout will be supplied during registration and will be used to add the post processing hook to all added cells. Signed-off-by: Michael Walle Tested-by: Michael Walle # on kontron-pitx-imx8m Signed-off-by: Miquel Raynal --- drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e9b52ecb3f72..ac0edb6398f1 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset, static int imx_ocotp_cell_pp(void *context, const char *id, int index, unsigned int offset, void *data, size_t bytes) { - struct ocotp_priv *priv = context; + u8 *buf = data; + int i; /* Deal with some post processing of nvmem cell data */ - if (id && !strcmp(id, "mac-address")) { - if (priv->params->reverse_mac_address) { - u8 *buf = data; - int i; - - for (i = 0; i < bytes/2; i++) - swap(buf[i], buf[bytes - i - 1]); - } - } + if (id && !strcmp(id, "mac-address")) + for (i = 0; i < bytes / 2; i++) + swap(buf[i], buf[bytes - i - 1]); return 0; } @@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .stride = 1, .reg_read = imx_ocotp_read, .reg_write = imx_ocotp_write, - .cell_post_process = imx_ocotp_cell_pp, }; static const struct ocotp_params imx6q_params = { @@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids); +static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem, + struct nvmem_layout *layout, + struct nvmem_cell_info *cell) +{ + cell->read_post_process = imx_ocotp_cell_pp; +} + +struct nvmem_layout imx_ocotp_layout = { + .fixup_cell_info = imx_ocotp_fixup_cell_info, +}; + static int imx_ocotp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.size = 4 * priv->params->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; + if (priv->params->reverse_mac_address) + imx_ocotp_nvmem_config.layout = &imx_ocotp_layout; + priv->config = &imx_ocotp_nvmem_config; clk_prepare_enable(priv->clk); From patchwork Tue Mar 7 16:53:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2544075wrd; Tue, 7 Mar 2023 09:03:58 -0800 (PST) X-Google-Smtp-Source: AK7set8KikvEC+7w5FXFEiohXqqkygE5KIsiaf/+30wb02TbHGNeuqfvAVwnGUnRGfRMCAwwHkSu X-Received: by 2002:a17:907:a602:b0:8f1:939b:9701 with SMTP id vt2-20020a170907a60200b008f1939b9701mr15951233ejc.66.1678208638557; Tue, 07 Mar 2023 09:03:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208638; cv=none; d=google.com; s=arc-20160816; b=05SthrgDeZO5GRefdINGWbfE/E+FBnWSsm//z9NGXMmax/qKhDvBPk+ELyzLuGwxaJ 1QdrhrCiQPCG+mt8Lb1ZOTuB9YjkF2hgvb14ndSh9blbT6wW0mit1Ys8kO/o50LWaJLb uxz/fr9iAcch7ndkri44ji0rSWNkyUfXMbtnaVzMk0gN9Al4WfCFfjQ8Cy2Fv2aZl2jK Vpw5QrXNWcfHLxslEZ9brTZhna+UexvDymsDkZFOHam8ICsYUEfV2a1CPVbDMT77NRJL M2z2V/8uB4vKMq0Yty24XMj4xl0X8KY83wqhU7DQYGl9Xfne1yKI6Feb3T1pS372drTQ Cs+g== 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=DwN8++5oxOIgSYePzy5PVeFCPn/l7NHxvR0eNwHxoIY=; b=G0AJT5/E8WZsElHM2FcQe2m8BH7g296Kp0/dQYkfpcpo9P8xfJC6TrdgPM6YMMUwke Qpnwr/OcgipJNxoPhdCk8WAWiqwV3+qTzoUWxyiNr3nmw1yr/hPLlfOmPEwxKDaX3fLB BCDtHGy4AI0M8D//eqD3rcbVgC8zB9yAWBSzo8ULomjkpfaDRZkIFx146mHVHB59/xyh MnBZ+QRrvmmv0OJm5rmPujog3ZuFv504dvDivrgk2qXcL/KG6qcDS287p7lvwsGj3jaX a2srKkQLssLSVsUa+GhecAEVIvBObJP51Aw+mCMapG0hYX+XRT+bL3VqSvFD9Qwgsb+i O7dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=AJ2Yizgd; 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 rs17-20020a170907037100b008dcebb5a109si10306350ejb.563.2023.03.07.09.03.33; Tue, 07 Mar 2023 09:03:58 -0800 (PST) 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=AJ2Yizgd; 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 S231393AbjCGQ75 (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230482AbjCGQ6M (ORCPT ); Tue, 7 Mar 2023 11:58:12 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 551E89009A; Tue, 7 Mar 2023 08:54:59 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 8EB8FC0007; Tue, 7 Mar 2023 16:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208097; 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=DwN8++5oxOIgSYePzy5PVeFCPn/l7NHxvR0eNwHxoIY=; b=AJ2YizgdA7smSYMK0mDqF39mE19zmeIEJ0v3fdjJG7WZJYpCKYZdEXUNUUVTY61WQqWLKX SkKeYZtx2bIgdv8/eiR+l9oIIr9huk3BEdkYQbmlqQY1kucxiqHh/Br0TWU2iJbFykXQk3 NuGTK45+jel8ZsbCm1vV9fXAiF9/Y3Aq/ecHSsUamlDw+2zYMrgaVWhaSZEDuojV7vl29C ECOOkIDlOJ8seAaevB3xXCYb0FGjzvCfgwP+LqjLwfZhgVhxuPoY9Zoh4/+bLD72BoGOko TN3Es7PhgYoA79GLaQeDTc7VM3VriNCosLrQLnPKBCB54pRAqmejC1v+5ORqKQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 16/21] nvmem: cell: drop global cell_post_process Date: Tue, 7 Mar 2023 17:53:54 +0100 Message-Id: <20230307165359.225361-17-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729301353093892?= X-GMAIL-MSGID: =?utf-8?q?1759729301353093892?= From: Michael Walle There are no users anymore for the global cell_post_process callback anymore. New users should use proper nvmem layouts. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 9 --------- include/linux/nvmem-provider.h | 2 -- 2 files changed, 11 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 82e11b9576ad..31d1d10c0e1c 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -39,7 +39,6 @@ struct nvmem_device { unsigned int nkeepout; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; - nvmem_cell_post_process_t cell_post_process; struct gpio_desc *wp_gpio; struct nvmem_layout *layout; void *priv; @@ -903,7 +902,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->type = config->type; nvmem->reg_read = config->reg_read; nvmem->reg_write = config->reg_write; - nvmem->cell_post_process = config->cell_post_process; nvmem->keepout = config->keepout; nvmem->nkeepout = config->nkeepout; if (config->of_node) @@ -1576,13 +1574,6 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, return rc; } - if (nvmem->cell_post_process) { - rc = nvmem->cell_post_process(nvmem->priv, id, index, - cell->offset, buf, cell->bytes); - if (rc) - return rc; - } - if (len) *len = cell->bytes; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index be81cc88eabc..d3d7af86a283 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -85,7 +85,6 @@ struct nvmem_cell_info { * @no_of_node: Device should not use the parent's of_node even if it's !NULL. * @reg_read: Callback to read data. * @reg_write: Callback to write data. - * @cell_post_process: Callback for vendor specific post processing of cell data * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. @@ -118,7 +117,6 @@ struct nvmem_config { bool no_of_node; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; - nvmem_cell_post_process_t cell_post_process; int size; int word_size; int stride; From patchwork Tue Mar 7 16:53:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2549208wrd; Tue, 7 Mar 2023 09:11:42 -0800 (PST) X-Google-Smtp-Source: AK7set9/PFjLaIkEu8yoD2ldGmwNTK8BmqERuAP1Dz101fG3zZZs7DckqAngNFffXiiTOrTbiQwj X-Received: by 2002:a05:6a20:8416:b0:b8:499d:7c9b with SMTP id c22-20020a056a20841600b000b8499d7c9bmr19110462pzd.51.1678209102038; Tue, 07 Mar 2023 09:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678209102; cv=none; d=google.com; s=arc-20160816; b=JvOqD8qXc0ir4A0j5iWOCfAqw7rKaHtwhlS7pk0at4C8fodumxjHUIjno35gbKyp1V TY11ZB9QqRniqvTsnqRoeui6VWNVNb9BDgdbpLqoHVZhsWcCfD5npEnpYFsq9F9SyAF0 liPTUUHlLWDgiYtUspBXNpam5C6VgOyxQcT91D11/oN/H+v6MlHqZBt+mIVc4WkiOw01 73stGvQ4tOkldvAL97fDtxdychdSLJ+Ir8JDr7hOusQ1E8GHa6ln26hd0u/WmHl2ueCM mveXl32+xm4I+jxfcmUYTrMEgdRB05KxQKFAmwbeWPBH5tfxJsWwk91dl30pmoSvUtiD 2cww== 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=Lm8Fo8GltNhElaI0RcGviH0CBmxuVxbmsI/nBgU01Rc=; b=szMsIYGduwRbDvAhd2OMc/0Zlj+6YpO5/GMb3xmuaB4wG+jcrNl85iFNdnaeJoKzrj u/IF5dWQbVxi8cEAyTFPjQwXbXgVVmnJqdXOgIHwMzO/Z+yMRMn0/QIjsODrlknS9m8Q 85Pn17gT7qDKFCcfFGlPdhAxdhqETZ3f1EXtyVUTrqQkdLfw/wpRVq90bDyu5HBJ7fav k5fJf3nDWzFzFmX49rrnXi7Gh6C+3617W1mF5948op0a7Y4hkTKolFLfIGHOX/hQrdUq LHgCIViqTC0eanuNDR3s8wLEElrMkrVduX8aTpABt6C+VMZqDWPlqykTBAA5Q9ouOhYv Bi9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=FrPKkgO+; 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 b4-20020a6567c4000000b004efc29aa16asi12125871pgs.102.2023.03.07.09.11.29; Tue, 07 Mar 2023 09:11:42 -0800 (PST) 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=FrPKkgO+; 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 S230034AbjCGRAb (ORCPT + 99 others); Tue, 7 Mar 2023 12:00:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231129AbjCGQ6N (ORCPT ); Tue, 7 Mar 2023 11:58:13 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A85EA943AD; Tue, 7 Mar 2023 08:55:00 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id F317EC0004; Tue, 7 Mar 2023 16:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208099; 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=Lm8Fo8GltNhElaI0RcGviH0CBmxuVxbmsI/nBgU01Rc=; b=FrPKkgO+1fcjp2bepCD+d6vTWTmXiUpGQ3IkRThmns1bDR1s2lSX6Pv9L2EXj2cUv4KdTd 3hAXz+eUmhKVhDV5izAIjL6168bfQGgaORJNR+CiV+i43z+btSOAwGxZ57jgU5yxrC4c8i voEs/YVJ+UdSYWhsROfWRMKYItbtZU5Fod3j74edqjuFh2JorRaMss2xu13rvmH7khJxTz fUJQVyLpJTl0lEwvUaCiwBI5Nux7STF8yen3lRf2E9pav1QRsVUtAw6V1IBIjms7HOEyRy fEns7dpG/0DnJTGA2FmoZyZmwhAHQW/cwVpYIFT8nGl5yhXTRUgsqWwOIGixEA== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 17/21] nvmem: core: provide own priv pointer in post process callback Date: Tue, 7 Mar 2023 17:53:55 +0100 Message-Id: <20230307165359.225361-18-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729787452883882?= X-GMAIL-MSGID: =?utf-8?q?1759729787452883882?= From: Michael Walle It doesn't make any more sense to have a opaque pointer set up by the nvmem device. Usually, the layout isn't associated with a particular nvmem device. Instead, let the caller who set the post process callback provide the priv pointer. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 +++- include/linux/nvmem-provider.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 31d1d10c0e1c..8e07b9df3221 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -54,6 +54,7 @@ struct nvmem_cell_entry { int bit_offset; int nbits; nvmem_cell_post_process_t read_post_process; + void *priv; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -471,6 +472,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->bytes = info->bytes; cell->name = info->name; cell->read_post_process = info->read_post_process; + cell->priv = info->priv; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1568,7 +1570,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, nvmem_shift_read_buffer_in_place(cell, buf); if (cell->read_post_process) { - rc = cell->read_post_process(nvmem->priv, id, index, + rc = cell->read_post_process(cell->priv, id, index, cell->offset, buf, cell->bytes); if (rc) return rc; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index d3d7af86a283..0cf9f9490514 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -20,7 +20,8 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); /* used for vendor specific post processing of cell data */ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, - unsigned int offset, void *buf, size_t bytes); + unsigned int offset, void *buf, + size_t bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, @@ -56,6 +57,7 @@ struct nvmem_keepout { * @np: Optional device_node pointer. * @read_post_process: Callback for optional post processing of cell data * on reads. + * @priv: Opaque data passed to the read_post_process hook. */ struct nvmem_cell_info { const char *name; @@ -65,6 +67,7 @@ struct nvmem_cell_info { unsigned int nbits; struct device_node *np; nvmem_cell_post_process_t read_post_process; + void *priv; }; /** From patchwork Tue Mar 7 16:53:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2551365wrd; Tue, 7 Mar 2023 09:15:39 -0800 (PST) X-Google-Smtp-Source: AK7set+toJt9eYQXEMtpPgvN61EePMzeP1uCqrttSwIQ+fx0ZDoYF6/KRCkseDko9wDB/DlPxxfs X-Received: by 2002:a17:90a:16:b0:23a:ad68:25a4 with SMTP id 22-20020a17090a001600b0023aad6825a4mr8073605pja.10.1678209339413; Tue, 07 Mar 2023 09:15:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678209339; cv=none; d=google.com; s=arc-20160816; b=aW1wlDG3oqGjA7nx6LCOh7TOgt6ybOzOx+2G9f0V2rAwuEeILsK7QM7S1uzu/UzXCb 07CSfeX4nB6Ox+s6676pdzvfHfVoNW6XitRdJ0oe2TpStUUHPJdTs0C+/Y1qUkYs6ppf mLbun94CAyiPOUUP987cSGj8bJ+jzTOgZTR8H03j2uRKQ91wDWbdR5DuskIWG6HyK62Y tae/NdV1/sOofQZOPG4Xw8GbaJP29glHtxrrL5f2icZFslEDU1qdFKYTb+IWN0NsEl44 jh02CYXKFNE9XBJ+MngVAAU8tuAxmtq4xNpmz8QsY4fKG87JgsPkj8aRpeTLVWcd2t7N GjpA== 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=uFRM4PTDCSOdcU0u0521ZO4/N4DtV8C7SzDo9oGW8ew=; b=rYCfmSb2V08OZ8Nr5AfCKmwNmL+o5FKJkzQe+Uf+FJdT2fzr+6vx/It0nChpOOY7F+ mK/pEgdi4JA0mzjSlTLjvvI7lmuOXASIBD18VveTMkYUH3NainCA05CVSCygokjjgnkH GqoiLB+WasTPAX1Mmp57Ra4uhDkrW14fBHCdNwoL5LXawuzvUTdHMhRNYsAl4UDI9A+t 1bX1n6M9ud7gVvmMjMM6ocmJuNtL4mJcYJS6tOxpIwmDdWesZvpaNXTHxtp3KFfFu7D0 DuNs7f5O1P/+z36zyExfXUSu3FaA7PKEEClt06d8VULnlcC5GZiRdXCQ1PiHmth7SWyk Weeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=btl4h8iC; 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 br22-20020a17090b0f1600b0022c2eb502bcsi12208792pjb.36.2023.03.07.09.15.26; Tue, 07 Mar 2023 09:15:39 -0800 (PST) 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=btl4h8iC; 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 S230147AbjCGRAf (ORCPT + 99 others); Tue, 7 Mar 2023 12:00:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbjCGQ6N (ORCPT ); Tue, 7 Mar 2023 11:58:13 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88268943B5; Tue, 7 Mar 2023 08:55:02 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 6072CC0005; Tue, 7 Mar 2023 16:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208101; 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=uFRM4PTDCSOdcU0u0521ZO4/N4DtV8C7SzDo9oGW8ew=; b=btl4h8iCTek/AtdkeYHXB+fPHhTUJ5g5mIXhhbt8qFN1Xqpb4IBP34sPOuQoFZbtePO23w DPYltHaZrJmkrqR+FcNi6fYY5bR0ygLDJtrL5riAuwWzzZVAP65mQH+zeJzy2VMMF9x/v+ ThYg+qHi30rtG8fZ9eAs+XrG9208342GLByaVE6MrOiLW1SuPlay+T1dojcEqLJFXPGfHe DH+jjRsTQj1OvVGsiVU9tBWKAoBNLx1MRZhNhwf+pQIwbiiiD37MB4748fJ8MDZMH2fCKh NHgI7jj0xrHDr5/JfMiEMQ9Zu0FCXCSjBX++zciYfmzr1Ay0J7nxhGlII4NV7Q== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 18/21] nvmem: layouts: sl28vpd: Add new layout driver Date: Tue, 7 Mar 2023 17:53:56 +0100 Message-Id: <20230307165359.225361-19-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759730035740458008?= X-GMAIL-MSGID: =?utf-8?q?1759730035740458008?= From: Michael Walle This layout applies to the VPD of the Kontron sl28 boards. The VPD only contains a base MAC address. Therefore, we have to add an individual offset to it. This is done by taking the second argument of the nvmem phandle into account. Also this let us checking the VPD version and the checksum. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 2 + drivers/nvmem/layouts/sl28vpd.c | 165 ++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 drivers/nvmem/layouts/sl28vpd.c diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 9ad3911d1605..fd161347c129 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -2,4 +2,13 @@ menu "Layout Types" +config NVMEM_LAYOUT_SL28_VPD + tristate "Kontron sl28 VPD layout support" + select CRC8 + help + Say Y here if you want to support the VPD layout of the Kontron + SMARC-sAL28 boards. + + If unsure, say N. + endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile index 6fdb3c60a4fa..fc617b9e87d0 100644 --- a/drivers/nvmem/layouts/Makefile +++ b/drivers/nvmem/layouts/Makefile @@ -2,3 +2,5 @@ # # Makefile for nvmem layouts. # + +obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c new file mode 100644 index 000000000000..9370e41bad73 --- /dev/null +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +#define SL28VPD_MAGIC 'V' + +struct sl28vpd_header { + u8 magic; + u8 version; +} __packed; + +struct sl28vpd_v1 { + struct sl28vpd_header header; + char serial_number[15]; + u8 base_mac_address[ETH_ALEN]; + u8 crc8; +} __packed; + +static int sl28vpd_mac_address_pp(void *priv, const char *id, int index, + unsigned int offset, void *buf, + size_t bytes) +{ + if (bytes != ETH_ALEN) + return -EINVAL; + + if (index < 0) + return -EINVAL; + + if (!is_valid_ether_addr(buf)) + return -EINVAL; + + eth_addr_add(buf, index); + + return 0; +} + +static const struct nvmem_cell_info sl28vpd_v1_entries[] = { + { + .name = "serial-number", + .offset = offsetof(struct sl28vpd_v1, serial_number), + .bytes = sizeof_field(struct sl28vpd_v1, serial_number), + }, + { + .name = "base-mac-address", + .offset = offsetof(struct sl28vpd_v1, base_mac_address), + .bytes = sizeof_field(struct sl28vpd_v1, base_mac_address), + .read_post_process = sl28vpd_mac_address_pp, + }, +}; + +static int sl28vpd_v1_check_crc(struct device *dev, struct nvmem_device *nvmem) +{ + struct sl28vpd_v1 data_v1; + u8 table[CRC8_TABLE_SIZE]; + int ret; + u8 crc; + + crc8_populate_msb(table, 0x07); + + ret = nvmem_device_read(nvmem, 0, sizeof(data_v1), &data_v1); + if (ret < 0) + return ret; + else if (ret != sizeof(data_v1)) + return -EIO; + + crc = crc8(table, (void *)&data_v1, sizeof(data_v1) - 1, 0); + + if (crc != data_v1.crc8) { + dev_err(dev, + "Checksum is invalid (got %02x, expected %02x).\n", + crc, data_v1.crc8); + return -EINVAL; + } + + return 0; +} + +static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + const struct nvmem_cell_info *pinfo; + struct nvmem_cell_info info = {0}; + struct device_node *layout_np; + struct sl28vpd_header hdr; + int ret, i; + + /* check header */ + ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr); + if (ret < 0) + return ret; + else if (ret != sizeof(hdr)) + return -EIO; + + if (hdr.magic != SL28VPD_MAGIC) { + dev_err(dev, "Invalid magic value (%02x)\n", hdr.magic); + return -EINVAL; + } + + if (hdr.version != 1) { + dev_err(dev, "Version %d is unsupported.\n", hdr.version); + return -EINVAL; + } + + ret = sl28vpd_v1_check_crc(dev, nvmem); + if (ret) + return ret; + + layout_np = of_nvmem_layout_get_container(nvmem); + if (!layout_np) + return -ENOENT; + + for (i = 0; i < ARRAY_SIZE(sl28vpd_v1_entries); i++) { + pinfo = &sl28vpd_v1_entries[i]; + + info.name = pinfo->name; + info.offset = pinfo->offset; + info.bytes = pinfo->bytes; + info.read_post_process = pinfo->read_post_process; + info.np = of_get_child_by_name(layout_np, pinfo->name); + + ret = nvmem_add_one_cell(nvmem, &info); + if (ret) { + of_node_put(layout_np); + return ret; + } + } + + of_node_put(layout_np); + + return 0; +} + +static const struct of_device_id sl28vpd_of_match_table[] = { + { .compatible = "kontron,sl28-vpd" }, + {}, +}; +MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); + +struct nvmem_layout sl28vpd_layout = { + .name = "sl28-vpd", + .of_match_table = sl28vpd_of_match_table, + .add_cells = sl28vpd_add_cells, +}; + +static int __init sl28vpd_init(void) +{ + return nvmem_layout_register(&sl28vpd_layout); +} + +static void __exit sl28vpd_exit(void) +{ + nvmem_layout_unregister(&sl28vpd_layout); +} + +module_init(sl28vpd_init); +module_exit(sl28vpd_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Michael Walle "); +MODULE_DESCRIPTION("NVMEM layout driver for the VPD of Kontron sl28 boards"); From patchwork Tue Mar 7 16:53:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2550375wrd; Tue, 7 Mar 2023 09:13:43 -0800 (PST) X-Google-Smtp-Source: AK7set+2U6d8Y44H9pGr5Xodxf0Gnn/RlocPjH6UVZHfPvyswNz508kNn7IdFORdmM87sk91XbQC X-Received: by 2002:a17:903:22c1:b0:19e:ba2c:27ec with SMTP id y1-20020a17090322c100b0019eba2c27ecmr11756525plg.11.1678209223423; Tue, 07 Mar 2023 09:13:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678209223; cv=none; d=google.com; s=arc-20160816; b=A42xyuH84ezYtwdgijdj1BXkojJoBaonyNKuUH8p7ZeklFNylpJ/3WzU4BhiC80syP PeXZ124AUJ2FasTpskjM6x0HxriJ5X8G0+9BCGtD2vH8w2qQQzNOXT7ajclPfjAZ/KQK 1Z7RRgHLkeReg/YXqSy78+HBMCr9vE6HNL9vMIHb5db0drJFb8489bks0/To9pAb2EJy cnlo3nkLm+/VxxiSNwAXkfcbmMo8OirJ9syHO/vzyfjgAFk34nbqay60n+/b+8XsuGQi XaPUi7idtQjtUoO4QqoAiSvVNCY8XkJ2gNbHjZJOmsK5sVw5512HPxqIDU4qZ3uSp8Z2 XY/g== 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=1sH7jIqmes/dFcqTUZTByGsS0wzqmOoQe1awigbM7hY=; b=uJMRxwkW0o6IZzeBZa4huSk1Yy9dJ6bsmCJJbHJCjrw0PWSud/lGI2QClCXeS8DVRQ bR84evMc3UOnMyki/9ZK4ZKlqI2+zzw+fOS5CCGLX2Oi7gJuOeVKLu7n1feOBBCP/plf M0tEWha0Cu0UpH0LTHfKJfvHJ/WfWnyckp0bDGE43D9U1turERMOeZqVtguDCfYg13Y7 comQsyCVb2+0bS4Z57KFsuHtoLgeDquzkb4QpK38RAdxJiVFmKO8wHrbGEmLHnW+1hjM 61s4MDuZxti0jnRUOuR9U6T2BQgJAD7xZKwp6A08gc1ZixtY0RleAD2GJNnlx60dWhP4 8XNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CceaZlEW; 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 i8-20020a170902c94800b0019ad97d72cfsi12843901pla.590.2023.03.07.09.13.30; Tue, 07 Mar 2023 09:13:43 -0800 (PST) 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=CceaZlEW; 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 S230240AbjCGRAm (ORCPT + 99 others); Tue, 7 Mar 2023 12:00:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229724AbjCGQ6U (ORCPT ); Tue, 7 Mar 2023 11:58:20 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45B340C9; Tue, 7 Mar 2023 08:55:04 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 95E2FC0008; Tue, 7 Mar 2023 16:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208103; 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=1sH7jIqmes/dFcqTUZTByGsS0wzqmOoQe1awigbM7hY=; b=CceaZlEWJarq/+3071RSzt3Qs0EYkVgJwbkNEuGmy4ncWA7lJ3nJq3UOZ1V/PI5Spn6AMe qnzC3Q33iDCN7ykePaQ2C0xgQe2U9oDJV0xJIN6+do8NBlu5GaEnYuEJjnmwJlCjNQci34 xOg0W+Uj7nUZLDkuwCmnO8ZRmMPMccSWNZZFxBW2W2+5SoGNSx/Ny/n8L5EIBnFe/Jd4td BN7+koXFOvQ8a/GBfFL5YeK+RHxGv8iagdrJ1dVi2iLOEXlTLjbD2AcoCode7NzwYrz1dA unos8rEyYfgcO1LrJQqSdjrSJvl+sP9AJ3Olukp0k5yC1Dq+H4OAr+Arj2YKcQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 19/21] MAINTAINERS: add myself as sl28vpd nvmem layout driver Date: Tue, 7 Mar 2023 17:53:57 +0100 Message-Id: <20230307165359.225361-20-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729914824219381?= X-GMAIL-MSGID: =?utf-8?q?1759729914824219381?= From: Michael Walle Add myself as a maintainer for the new sl28vpd nvmem layout driver. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index f61eb221415b..70aa4547d784 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19178,6 +19178,12 @@ F: drivers/irqchip/irq-sl28cpld.c F: drivers/pwm/pwm-sl28cpld.c F: drivers/watchdog/sl28cpld_wdt.c +SL28 VPD NVMEM LAYOUT DRIVER +M: Michael Walle +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml +F: drivers/nvmem/layouts/sl28vpd.c + SLAB ALLOCATOR M: Christoph Lameter M: Pekka Enberg From patchwork Tue Mar 7 16:53:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2550059wrd; Tue, 7 Mar 2023 09:13:09 -0800 (PST) X-Google-Smtp-Source: AK7set/LGxjT1DIH0VPYFjwC8ekBcm5diaszR8UhDehxfmHq3LKc+zuhbQ3FgZIDWCrrWohzkOFO X-Received: by 2002:a17:902:e88e:b0:19c:df17:7c8e with SMTP id w14-20020a170902e88e00b0019cdf177c8emr18695970plg.68.1678209189285; Tue, 07 Mar 2023 09:13:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678209189; cv=none; d=google.com; s=arc-20160816; b=Qu0x12PiFEVWEX/Gk7w8NaINy057GNuhG35kk2hdSuk9fya2+5h41+kJEIR0GOw4Ly K2arnaHohQ7V8bFdqGfmnbw24SXbgH39AdTTHZr7yE1+/yObm1K4gbZpQYaWzRZeB4bD a1Bh3MMUdo9erOf17tEMkZfPiU92lsvv8zaznHXS6SjdM4mFIh5kgVVez5VFXhsLhNBM dzYiWyHdyZpS0Vbw6nZiSAvI3KePX5S9FgghmyrciKS40CJLwObpl1XNgLGhkZDXL6hB N3AMRyjOPgr/hTyrEpsT49TrTq6/f79w8iPXti1t33g0RIj9arT98Ev5Pne3mrHLPF7W urRw== 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=5r6F0YpgjdYq8KoLnNlw94ikIMFZ53LzHkMcfFlQ/Ds=; b=ooYl7l3Ctn+J0wq2MqmWrQ28tvFE+GXhp+PDY/2LWGC0Dr3c7gBm6YhdN/QaFHqeXK G8ylSOmt1O+HK/WkfP420RfcRwvCOsykah/gQ6YuY/Yem81gvwkcaLu9wZPBDshrpADy ZRZVlNp/oSW20UXWKWSJqwulLnjG0QIHbKn+KWpbWu66n9QditpTCDfn6gyGGwFf88E/ iQfMe9d23iy1ifWRLfC/20RPcPP/N1HUutM2m4m+5lk3j+jVbHo4Xy8oBgc5nVpyki5+ 5dQ7icnY4mjSD2bLN02zPSXoXoL7ppxUU+Lbtrz5/6d6cmhVROW4A6cwTNQqrjUzGeSt rsJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=DDcNiMF4; 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 e1-20020a17090301c100b0019c368e8a68si13742713plh.610.2023.03.07.09.12.55; Tue, 07 Mar 2023 09:13:09 -0800 (PST) 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=DDcNiMF4; 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 S230375AbjCGRAp (ORCPT + 99 others); Tue, 7 Mar 2023 12:00:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbjCGQ6t (ORCPT ); Tue, 7 Mar 2023 11:58:49 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2705B34334; Tue, 7 Mar 2023 08:55:15 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B42F7C0007; Tue, 7 Mar 2023 16:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208113; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5r6F0YpgjdYq8KoLnNlw94ikIMFZ53LzHkMcfFlQ/Ds=; b=DDcNiMF4VbXE/BRm0bnDJ1epuqpT9wM/R5iH7jzhbhflk0wGZoHjzYOrjQdYgCb8QCOLLH 5ncQ6iq6q9DKqQzRtFDFYm1svSo9+t1869KeLSVwOrMRDLeQQ+7chnvhTvB2EZV3YOelsT 5bH+4L8ERjNASs8Jh9gc1W7VafsQV4Lc3MveinLcXZAugvPj0NftnNQCc6szsHOf2CzWs7 WElbw/8eBE5HGEIX9ebljxeW8G8j7HjJOe4fKNLEkAPB/xyzanXIMTWSUkZtms9Dg4sA+9 IZgzJwzBTIEQYf8E1ryqDM5wgNM3Oo8cRH6nUzHgudcxIdNmcDRRpTTJpfIfzg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 20/21] nvmem: layouts: onie-tlv: Add new layout driver Date: Tue, 7 Mar 2023 17:53:58 +0100 Message-Id: <20230307165359.225361-21-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729878442809263?= X-GMAIL-MSGID: =?utf-8?q?1759729878442809263?= This layout applies on top of any non volatile storage device containing an ONIE table factory flashed. This table follows the tlv (type-length-value) organization described in the link below. We cannot afford using regular parsers because the content of these tables is manufacturer specific and must be dynamically discovered. Link: https://opencomputeproject.github.io/onie/design-spec/hw_requirements.html Signed-off-by: Miquel Raynal --- drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 1 + drivers/nvmem/layouts/onie-tlv.c | 257 +++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 drivers/nvmem/layouts/onie-tlv.c diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index fd161347c129..7ff1ee1c1f05 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -11,4 +11,13 @@ config NVMEM_LAYOUT_SL28_VPD If unsure, say N. +config NVMEM_LAYOUT_ONIE_TLV + tristate "ONIE tlv support" + select CRC32 + help + Say Y here if you want to support the Open Compute Project ONIE + Type-Length-Value standard table. + + If unsure, say N. + endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile index fc617b9e87d0..2974bd7d33ed 100644 --- a/drivers/nvmem/layouts/Makefile +++ b/drivers/nvmem/layouts/Makefile @@ -4,3 +4,4 @@ # obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o +obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c new file mode 100644 index 000000000000..d45b7301a69d --- /dev/null +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ONIE tlv NVMEM cells provider + * + * Copyright (C) 2022 Open Compute Group ONIE + * Author: Miquel Raynal + * Based on the nvmem driver written by: Vadym Kochan + * Inspired by the first layout written by: Rafał Miłecki + */ + +#include +#include +#include +#include +#include + +#define ONIE_TLV_MAX_LEN 2048 +#define ONIE_TLV_CRC_FIELD_SZ 6 +#define ONIE_TLV_CRC_SZ 4 +#define ONIE_TLV_HDR_ID "TlvInfo" + +struct onie_tlv_hdr { + u8 id[8]; + u8 version; + __be16 data_len; +} __packed; + +struct onie_tlv { + u8 type; + u8 len; +} __packed; + +static const char *onie_tlv_cell_name(u8 type) +{ + switch (type) { + case 0x21: + return "product-name"; + case 0x22: + return "part-number"; + case 0x23: + return "serial-number"; + case 0x24: + return "mac-address"; + case 0x25: + return "manufacture-date"; + case 0x26: + return "device-version"; + case 0x27: + return "label-revision"; + case 0x28: + return "platform-name"; + case 0x29: + return "onie-version"; + case 0x2A: + return "num-macs"; + case 0x2B: + return "manufacturer"; + case 0x2C: + return "country-code"; + case 0x2D: + return "vendor"; + case 0x2E: + return "diag-version"; + case 0x2F: + return "service-tag"; + case 0xFD: + return "vendor-extension"; + case 0xFE: + return "crc32"; + default: + break; + } + + return NULL; +} + +static int onie_tlv_mac_read_cb(void *priv, const char *id, int index, + unsigned int offset, void *buf, + size_t bytes) +{ + eth_addr_add(buf, index); + + return 0; +} + +static nvmem_cell_post_process_t onie_tlv_read_cb(u8 type, u8 *buf) +{ + switch (type) { + case 0x24: + return &onie_tlv_mac_read_cb; + default: + break; + } + + return NULL; +} + +static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem, + size_t data_len, u8 *data) +{ + struct nvmem_cell_info cell = {}; + struct device_node *layout; + struct onie_tlv tlv; + unsigned int hdr_len = sizeof(struct onie_tlv_hdr); + unsigned int offset = 0; + int ret; + + layout = of_nvmem_layout_get_container(nvmem); + if (!layout) + return -ENOENT; + + while (offset < data_len) { + memcpy(&tlv, data + offset, sizeof(tlv)); + if (offset + tlv.len >= data_len) { + dev_err(dev, "Out of bounds field (0x%x bytes at 0x%x)\n", + tlv.len, hdr_len + offset); + break; + } + + cell.name = onie_tlv_cell_name(tlv.type); + if (!cell.name) + continue; + + cell.offset = hdr_len + offset + sizeof(tlv.type) + sizeof(tlv.len); + cell.bytes = tlv.len; + cell.np = of_get_child_by_name(layout, cell.name); + cell.read_post_process = onie_tlv_read_cb(tlv.type, data + offset + sizeof(tlv)); + + ret = nvmem_add_one_cell(nvmem, &cell); + if (ret) { + of_node_put(layout); + return ret; + } + + offset += sizeof(tlv) + tlv.len; + } + + of_node_put(layout); + + return 0; +} + +static bool onie_tlv_hdr_is_valid(struct device *dev, struct onie_tlv_hdr *hdr) +{ + if (memcmp(hdr->id, ONIE_TLV_HDR_ID, sizeof(hdr->id))) { + dev_err(dev, "Invalid header\n"); + return false; + } + + if (hdr->version != 0x1) { + dev_err(dev, "Invalid version number\n"); + return false; + } + + return true; +} + +static bool onie_tlv_crc_is_valid(struct device *dev, size_t table_len, u8 *table) +{ + struct onie_tlv crc_hdr; + u32 read_crc, calc_crc; + __be32 crc_be; + + memcpy(&crc_hdr, table + table_len - ONIE_TLV_CRC_FIELD_SZ, sizeof(crc_hdr)); + if (crc_hdr.type != 0xfe || crc_hdr.len != ONIE_TLV_CRC_SZ) { + dev_err(dev, "Invalid CRC field\n"); + return false; + } + + /* The table contains a JAMCRC, which is XOR'ed compared to the original + * CRC32 implementation as known in the Ethernet world. + */ + memcpy(&crc_be, table + table_len - ONIE_TLV_CRC_SZ, ONIE_TLV_CRC_SZ); + read_crc = be32_to_cpu(crc_be); + calc_crc = crc32(~0, table, table_len - ONIE_TLV_CRC_SZ) ^ 0xFFFFFFFF; + if (read_crc != calc_crc) { + dev_err(dev, "Invalid CRC read: 0x%08x, expected: 0x%08x\n", + read_crc, calc_crc); + return false; + } + + return true; +} + +static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + struct onie_tlv_hdr hdr; + size_t table_len, data_len, hdr_len; + u8 *table, *data; + int ret; + + ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr); + if (ret < 0) + return ret; + + if (!onie_tlv_hdr_is_valid(dev, &hdr)) { + dev_err(dev, "Invalid ONIE TLV header\n"); + return -EINVAL; + } + + hdr_len = sizeof(hdr.id) + sizeof(hdr.version) + sizeof(hdr.data_len); + data_len = be16_to_cpu(hdr.data_len); + table_len = hdr_len + data_len; + if (table_len > ONIE_TLV_MAX_LEN) { + dev_err(dev, "Invalid ONIE TLV data length\n"); + return -EINVAL; + } + + table = devm_kmalloc(dev, table_len, GFP_KERNEL); + if (!table) + return -ENOMEM; + + ret = nvmem_device_read(nvmem, 0, table_len, table); + if (ret != table_len) + return ret; + + if (!onie_tlv_crc_is_valid(dev, table_len, table)) + return -EINVAL; + + data = table + hdr_len; + ret = onie_tlv_add_cells(dev, nvmem, data_len, data); + if (ret) + return ret; + + 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 int __init onie_tlv_init(void) +{ + return nvmem_layout_register(&onie_tlv_layout); +} + +static void __exit onie_tlv_exit(void) +{ + nvmem_layout_unregister(&onie_tlv_layout); +} + +module_init(onie_tlv_init); +module_exit(onie_tlv_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Miquel Raynal "); +MODULE_DESCRIPTION("NVMEM layout driver for Onie TLV table parsing"); +MODULE_ALIAS("NVMEM layout driver for Onie TLV table parsing"); From patchwork Tue Mar 7 16:53:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2544855wrd; Tue, 7 Mar 2023 09:04:59 -0800 (PST) X-Google-Smtp-Source: AK7set8r/+jUDvltIv/c7eaNEBaH1hGHqbQ5TkOaludPuel52GDXCX4jn4Kk9UuZaR7ycrb8mMqh X-Received: by 2002:aa7:d683:0:b0:4af:75fd:8214 with SMTP id d3-20020aa7d683000000b004af75fd8214mr11833256edr.38.1678208699379; Tue, 07 Mar 2023 09:04:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208699; cv=none; d=google.com; s=arc-20160816; b=mJSXnW5h4LqNsst12OSbXngddKhw9NNe1htrQH6gBPcwYPzsanbCgPKgPFusVBL9nD dMpRRIrBGkTmabxDMj6PnRCXkmA2oUCtUpYNaVAQhUjG5B20Lb28LaDOaK9Pu56gGZ/q bl6XsXuitDA8ZXx673OFVqtSj9CPCK+rngLgHQxSnTP+Mizy+RXB+Imm8rFt9i7oGKHQ xKymNTj1FZPnCGb4wEvOI9CnbZHRaOSm7KcCfgiMYv/eVxbP6vrWhBRReKGIsvtVkQKV DD6tMxNk5KZ99g3HBOleMsrHhdhvZGpJOtjFg49m4wrW8VmWCLHsc/JFpB+3NpotvIyG C0dw== 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=k63jGN/pF5yVaAtIx4C9Ich6YXdGC8EJlNRF1GK/q1I=; b=sUxqlDAZvoekp3SubJjj0GxjJ8izvT6XZgevw4PHXi8VFrcMwxbxwcmo/luHCYEuoz ljfsh72akfXpD6Fja4JU8q8a45NRvB7rJJDr8T0wdwQ11ELJD6lsE7q8yecv6Svbv4ym DZi3VAdXJHmPEHWzF8agRTWpWa+vNO6dUFeWNCQcnHGvVaVL0ACvda7QPLlElfuiagJ9 tTfHv4a15Punt4G3gWwZfV+NBS49jv7J2CW2FJwxQdzk6IQt65gTSUSN1OWoZIZ9yT00 DiCbNr9mm2+C34iUb2PeZUv6DzDUS8r8zaXZW/yXnqrBZg7BFAPCfKb6zeE0pL1/DjO6 EAyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="UFBRY4l/"; 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 r5-20020aa7c145000000b004ad0affbc61si15109998edp.135.2023.03.07.09.04.31; Tue, 07 Mar 2023 09:04:59 -0800 (PST) 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="UFBRY4l/"; 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 S230433AbjCGRAu (ORCPT + 99 others); Tue, 7 Mar 2023 12:00:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbjCGQ6v (ORCPT ); Tue, 7 Mar 2023 11:58:51 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8175E943BC; Tue, 7 Mar 2023 08:55:20 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 3F2D4C000A; Tue, 7 Mar 2023 16:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208119; 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=k63jGN/pF5yVaAtIx4C9Ich6YXdGC8EJlNRF1GK/q1I=; b=UFBRY4l/f08YOv+HYmfpChl6+sKBr3zSHIW7SXpp4bKwfeufsZPq1IsDhyAzOmm047DR+0 9R++NTCF2LyrXgZTT3rJnUhVvm8CPYRIbwH2lD24DoHadXsRsqA1b55QFAh7UKwpK2O+jC PaHVdYBhp/QRio55ivxzKm2ztdvm6EJ3z+eQqOeq4yKg02abSwqJTdFiRdjF9tBJDwBgYw 6M8BPviPJgdHwdw1Y7pe/2EC1UtMZdhut64C6H/n9bLE9qttt3yPM/5m7SA1YZaR51nAxw aLW3pS2fEAAOu8XNHGFrxAoK+rS61UJffI7S5gv9V7yessuyF4pj6Cw1Mv1Isw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 21/21] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Date: Tue, 7 Mar 2023 17:53:59 +0100 Message-Id: <20230307165359.225361-22-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729364722020561?= X-GMAIL-MSGID: =?utf-8?q?1759729364722020561?= Following the introduction of the bindings for this NVMEM parser and the layout driver, add myself as maintainer. Signed-off-by: Miquel Raynal --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 70aa4547d784..60b8f2c07e7f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15577,6 +15577,12 @@ L: linux-hwmon@vger.kernel.org S: Maintained F: drivers/hwmon/oxp-sensors.c +ONIE TLV NVMEM LAYOUT DRIVER +M: Miquel Raynal +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml +F: drivers/nvmem/layouts/onie-tlv.c + ONION OMEGA2+ BOARD M: Harvey Hunt L: linux-mips@vger.kernel.org