From patchwork Wed Mar 1 15:22:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3692390wrd; Wed, 1 Mar 2023 07:25:03 -0800 (PST) X-Google-Smtp-Source: AK7set818cXOpug7PB7iVJzPIAiqYc0/VNJzFGJ3HLENGrVBF0SK/d1x8P6ej0mGmHE81GxYNPSW X-Received: by 2002:a17:906:b192:b0:889:ed81:dff7 with SMTP id w18-20020a170906b19200b00889ed81dff7mr7137117ejy.9.1677684303020; Wed, 01 Mar 2023 07:25:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684303; cv=none; d=google.com; s=arc-20160816; b=ue3lXWB3wPGg+c79mmBx4EExLXPFz3xy0iZxanQP6uckN4dFXoyCbDXt5rVIYegr4I 9x8hddJ885tBtSMx+yUEINmYLIPw/O7MpTV+pA3rpqMTkLPBXN8uxd3NwHlmuJ1mFolt OdyQkaKJVA1aQdlnO9MTNrKRL7mEKnleI7eon33k/ILiY/C7iBS3V13qE4wrx3/qhVEF GKDMAPdKjhW9oguINAHsAGtk1loHkNxp4vFnOsZo5jVTYC00xA1nvZuEcfCZXceUhvzm 4L3fbmAjQn4WKWrhZJGjU6gk20sr/tqXJuTsqxFKCN0EA38DopaJ7yOfD/MuHz3bLFFX bLUw== 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=D5n3KQw5FkYOO2ZCdrhHgke1RNc7JrIvX3lBsallp24=; b=o8ZguT41tU55xTja9eE+Eb5gojUhVwydACr40rEIhOEJ6rhylmgWhXON6nYGiMIY8A YQTUwQ/hEXi+Uar+K1pgooqnNwreqakew5Y0xhXJDgeUoW3H6/U3dZOX8iX9vEw9dS9t dHRHMDvcq4HNlDf4mssTV0s1O6YrSUtXs7T+I7CrTxz72dUl2W3HCApfAZDhnCPW0FkP WWOFtFgMqNjcWeH9ETGsl+EIAeHOv5iX+tRN1MqsZWbDmq+Y14mWv57EfbU4sHfH5bVF lvkAVwudyRCWLOQDuAIIl5NKjoCjr6vnkDVLyRY79yN0uUvoGk9ndtVhp71Vr7wQmq/f 1L6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Kj2GBS6P; 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 r3-20020a170906a20300b008e86646e6c5si2669412ejy.780.2023.03.01.07.24.38; Wed, 01 Mar 2023 07:25:03 -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=Kj2GBS6P; 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 S230310AbjCAPWu (ORCPT + 99 others); Wed, 1 Mar 2023 10:22:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjCAPWq (ORCPT ); Wed, 1 Mar 2023 10:22:46 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C7E043468; Wed, 1 Mar 2023 07:22:44 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id AF9D160012; Wed, 1 Mar 2023 15:22:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D5n3KQw5FkYOO2ZCdrhHgke1RNc7JrIvX3lBsallp24=; b=Kj2GBS6PPrHijhJPSkrA4vv0KT5OEQjjPzF/nW8BXycugB6Xu2gjOknzG/damIwd2TRanB 1c0enPgMMA8IIszMLk2A2lUxLYou1ZnsNAfPMRSq9UfHRxc2P9tFLXj26oYAbc4GVC4eQN 0KNTTxCFwb+Q76V4T85IG3UhO47piXTUvwK3hJ6FwBGavwT29CLzVbM9dOuJFJb2ToXDjr OTrUQwOkQ2BRS77IXkpqxx9cxjVlAmOP0CcazAKndeBIaTnOp8cdYqdh8H2EI2dOp0YE4J 1zW8buw6ZSfccyYSDnVdkAZpjvXYOopBMxsVq0Sh06xby1+8nOpZXdumZuoSWQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal , Stephen Boyd , Peter Chen Subject: [PATCH 1/8] of: Fix modalias string generation Date: Wed, 1 Mar 2023 16:22:32 +0100 Message-Id: <20230301152239.531194-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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 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?1759179495825827970?= X-GMAIL-MSGID: =?utf-8?q?1759179495825827970?= 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 Wed Mar 1 15:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62959 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3692731wrd; Wed, 1 Mar 2023 07:25:37 -0800 (PST) X-Google-Smtp-Source: AK7set+42YY+kJo/sGu+Iz+ri4Cxht47oHNx47Xx1lDIgTInWirxNPb2g5x/XZZhaAgeuTvNj6bi X-Received: by 2002:aa7:c498:0:b0:474:a583:2e1a with SMTP id m24-20020aa7c498000000b00474a5832e1amr6264114edq.12.1677684337360; Wed, 01 Mar 2023 07:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684337; cv=none; d=google.com; s=arc-20160816; b=JkmIBLuIDq/Bq2C6+/9z9QwytgeV7idXzy1x3zCsjAa+U8DFwaHXKkLmd3MtzmwEK6 fDSlJ5OwlLZ+0/C3wO5jxkHZG7t5TikR7q+MJrJCnJPU2YkvKcMZgy1bsdB2M4jLotQI l2sIpm6fqv0/LyNMeALk2JsP1WYWEXZYpiOsg+XvVGYsz+Pof31CkzWmqPMq7GmezhXY CTM7cGxEaAZ30eF7lAf2oZVN/5dbVXlqrjd0lwzhn0pZ4SzGf8Wx1QrwhVFCDEeGBidP rB6O9CokaXVaept1xH1uCFoDOnODMiaTg/kY6CQzos7gu5KNVNqNSwPL+8gJx5QPLgw6 1n0A== 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=+7AJrEMliVgBGap4LkX/HwlJ+8DgiboSpzHjInCtEXM=; b=AJ2Pgw6geWQDZmMeRgMQHYrkfvUC75QEr8ePNG0ADqa32CxSttuKepjquSx1Sradhd zCMolungnwmea1QyHFjvt0Qh4x/0bQK9biw6DDzzrLkj1riaUdaoSvKDqPYWKIlSYRZb hjPuiWCulfk4Pf49VafwsyE0o4grn8h8eQBlDBy5tJAEh2JvBCqd2afYfwfq6u1P2YiS ELPkZ+34AawHx8NRSnfhdcnOOOLqsHqlV4rFk2T+45BoE3PwAzuVaV4St1mOwWr9tEUc mrq+O1/pdYXxyYt+b0wRIB7NFEv9Ilw0FwfxJbqP1uccRYtSaKGVEldQFXxm42qaEk5b eU4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=IQjaQf6S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020aa7d512000000b004aab23dec62si1792479edq.37.2023.03.01.07.25.14; Wed, 01 Mar 2023 07:25:37 -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=IQjaQf6S; 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 S230343AbjCAPXE (ORCPT + 99 others); Wed, 1 Mar 2023 10:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230299AbjCAPWs (ORCPT ); Wed, 1 Mar 2023 10:22:48 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C801A43913; Wed, 1 Mar 2023 07:22:45 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 195366000E; Wed, 1 Mar 2023 15:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+7AJrEMliVgBGap4LkX/HwlJ+8DgiboSpzHjInCtEXM=; b=IQjaQf6SnB4xzp2ZcsKZdwwmYbgP6zO+qx9MDcHhTY3LB0uttv5GFdaJ10fIpeEOkXtuxc O8iwOHhZFYR0+rdGC2DcMefWDub/i3h1R059kyct7yg8dNOUphv8MGq9S7RMF0v18AkUXR 3ABsklzeBxg6psCn/3Q+akkRUFSjd0Lyp4+uaB9opG6Up6/IKSNv+OUGjR6KuPQHhW65Wu rmkqR4GiSQanxQqvGs683wK8blJec9eqdlSNM6K+GJKL2Z1EeOuU1w2v78H8PADr/C5Kej m8BHqEp5TdUtujborz+WU5IJ/NuiZrHaHYLMvvIkqI1hbh62YNL1yVHz6F/GqQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 2/8] of: Change of_device_get_modalias() main argument Date: Wed, 1 Mar 2023 16:22:33 +0100 Message-Id: <20230301152239.531194-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759179532040632344?= X-GMAIL-MSGID: =?utf-8?q?1759179532040632344?= This function needs "struct device_node" to work, but for convenience the author and only user of this helper did use a "struct device". As this helper is a static helper, let's keep the "struct device" for exported methods and use the OF structure internally. Signed-off-by: Miquel Raynal --- drivers/of/device.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 877f50379fab..3efc17de1d57 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -248,7 +248,7 @@ const void *of_device_get_match_data(const struct 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_device_get_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_device_get_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_device_get_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_device_get_modalias(dev->of_node, str, len - 2); if (sl < 0) return sl; if (sl > len - 2) @@ -386,7 +391,7 @@ int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) if (add_uevent_var(env, "MODALIAS=")) return -ENOMEM; - sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], + sl = of_device_get_modalias(dev->of_node, &env->buf[env->buflen-1], sizeof(env->buf) - env->buflen); if (sl >= (sizeof(env->buf) - env->buflen)) return -ENOMEM; From patchwork Wed Mar 1 15:22:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62957 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3692559wrd; Wed, 1 Mar 2023 07:25:22 -0800 (PST) X-Google-Smtp-Source: AK7set+RS8uoSB2nNJ5jYhksh/K6vrGZlwfmTiD29aq6gFq/LtnvpaK9FdkFFXUb4g2H+cHvWr+p X-Received: by 2002:a17:906:dc90:b0:888:5d34:dc79 with SMTP id cs16-20020a170906dc9000b008885d34dc79mr9379074ejc.40.1677684322642; Wed, 01 Mar 2023 07:25:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684322; cv=none; d=google.com; s=arc-20160816; b=0aJMo/psldsEoa4atecgVoohrqattKutMXbJz6OQXi8Tg4HRU7UsPe2xptx6LUSwQD MHjN1SS5knBMFwzkENwdhAW12X7OPpJnbI/jp0HO7SCS+bGyB42i8XXCLzyBllkZ8bue 4pEGfMC8Y4Zs1ahaU14CFEqvhe+aS/w/80/JXnhoxPU/YBQGFPRMoyWLDXWZs3/9J0bU aLm6u4v7w5n+QRtamGuB96T1hS8PPqmYVuIPBeDF2dbZ0BpztJDLZUeCJTntY6fUeIYh 3+d83k8opXYFD8sD1guY1exPPMm3wfFQ29oYQEbV0zVotoYDZ2rYJiNAiO2lPUACJAU0 S2XQ== 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=20ZNMpm9x0asQsEVva+trdnvABlBWfMLwEchVbLYbKo=; b=Sr+Vg/kP4ReAG9zYGAm7YaO64x6cYKwJKc/zaNdZeIX8OnKiXXAtiZbAD5S+OHPKXG fASzPFuD9824BvtQswylMYSqTs7E6w/EKgs9QOeB7B2cJmYvliHKdq6wTzJ2tbNbrRIi luNDyW0OTW3pa5ND3Nw+TcxiQbwqQKdmGfSmOgVsLrm+FQ0qOfGFbtzoaY2J+QVyhLXn SHs6TjTpj6BTkm7LpPlbtREOrXqhsqQaKIKFNVtMU7crd/M8ZFXH3qzR6k9Jkd2TRJCe nrI9kNWIG4cHeNb6U7uy9aqETJOYZyR7ep6vwx6zciW4491vz0XX6m3svugl1ZKBpKpX 3F5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=cRlym06t; 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 y4-20020aa7ccc4000000b004acc9d7aa34si2712532edt.550.2023.03.01.07.24.59; Wed, 01 Mar 2023 07:25:22 -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=cRlym06t; 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 S230329AbjCAPWz (ORCPT + 99 others); Wed, 1 Mar 2023 10:22:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbjCAPWt (ORCPT ); Wed, 1 Mar 2023 10:22:49 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F75C3BD86; Wed, 1 Mar 2023 07:22:46 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 4B3AC6000A; Wed, 1 Mar 2023 15:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=20ZNMpm9x0asQsEVva+trdnvABlBWfMLwEchVbLYbKo=; b=cRlym06tZywCTPZhMhhv3ejIASwMs5VLbcTsNBcHZ3o0jWWg0M9dCON5Yyx7mCgKEEPUtb RWFM72XRkmW45Igkq0jpfvDReypUSHR1o6ArajPEmtayJbqooqqoEucsZRRVBrXt1BbNrE dKj71kyVTXwuamyI2hKY2o331MivzHDWKD98BLIvQGjFQDE44ICEziO0vTaa5nbYk3uTNF Ht3R5I4MWq4GqVskw9ng7H8XJEO8ZBbvzKJ/cNvXHBMi7cFrgsQ17uY0WcW1+9Ltszx6f3 2oBlyP8hBNBPSFC80N3wawL/UQb1t4FXHYtzWpwKLPjoKM9Pk1rd2Vvo483buQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 3/8] of: Create an of_device_request_module() receiving an OF node Date: Wed, 1 Mar 2023 16:22:34 +0100 Message-Id: <20230301152239.531194-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759179516114199068?= X-GMAIL-MSGID: =?utf-8?q?1759179516114199068?= of_device_request_module() currently receives a "struct device" as main argument, but the only use of this pointer is to access its .of_node member. In practice, this function only needs a "struct device_node". Let's move the logic into another helper which would receive a "struct device_node" instead, and use that new helper from the ancient of_device_request_module(). Exporting this new function will be useful to request module loading when the "struct device" is not available. Signed-off-by: Miquel Raynal --- drivers/of/device.c | 17 +++++++++++++---- include/linux/of_device.h | 6 ++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 3efc17de1d57..7cdf252b9526 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -284,16 +284,16 @@ static ssize_t of_device_get_modalias(struct device_node *np, char *str, ssize_t return tsize; } -int of_device_request_module(struct device *dev) +int of_device_node_request_module(struct device_node *np) { char *str; ssize_t size; int ret; - if (!dev || !dev->of_node) + if (!np) return -ENODEV; - size = of_device_get_modalias(dev->of_node, NULL, 0); + size = of_device_get_modalias(np, NULL, 0); if (size < 0) return size; @@ -304,13 +304,22 @@ int of_device_request_module(struct device *dev) if (!str) return -ENOMEM; - of_device_get_modalias(dev->of_node, str, size); + of_device_get_modalias(np, str, size); str[size - 1] = '\0'; ret = request_module(str); kfree(str); return ret; } +EXPORT_SYMBOL_GPL(of_device_node_request_module); + +int of_device_request_module(struct device *dev) +{ + if (!dev) + return -ENODEV; + + return of_device_node_request_module(dev->of_node); +} EXPORT_SYMBOL_GPL(of_device_request_module); /** diff --git a/include/linux/of_device.h b/include/linux/of_device.h index ab7d557d541d..8918f9071ffb 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -33,6 +33,7 @@ extern void of_device_unregister(struct platform_device *ofdev); extern const void *of_device_get_match_data(const struct device *dev); extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len); +extern int of_device_node_request_module(struct device_node *np); extern int of_device_request_module(struct device *dev); extern void of_device_uevent(const struct device *dev, struct kobj_uevent_env *env); @@ -78,6 +79,11 @@ static inline int of_device_modalias(struct device *dev, return -ENODEV; } +static inline int of_device_node_request_module(struct device_node *np) +{ + return -ENODEV; +} + static inline int of_device_request_module(struct device *dev) { return -ENODEV; From patchwork Wed Mar 1 15:22:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62958 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3692580wrd; Wed, 1 Mar 2023 07:25:24 -0800 (PST) X-Google-Smtp-Source: AK7set/P3EKGnGn3yR7dJY6ocM+8kDmE06XGhSX7K7o6/17H166Q3a4OaxgYG53G1Dtb0Z1o5Vqn X-Received: by 2002:a17:906:3b85:b0:8b1:7569:b51a with SMTP id u5-20020a1709063b8500b008b17569b51amr6389610ejf.53.1677684324564; Wed, 01 Mar 2023 07:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684324; cv=none; d=google.com; s=arc-20160816; b=CmqVuKhMAt7l4MOWjAeLUarP+wQmQyZVc/JmgDTPTl7e4BwsR9tHSiA1qGF+3jBEUc h4Dq4wZyqsuxtFR+69Ms3PB4R3J/PdbbSBGBX2pB4UbeImhcJpUQS0KJF3dPCMW1VvOq 0CvcosIpWmMuWrTTwk0FKJ6BuBXZ7yrAHiEVtYfN0ejUOz+xMTSElsmep5Sxn5JsPb3F DLLiGaF15e9LPw1LVcbPjvSdxl0oDPLoA3sJJ2eaiWtO15hkaUSL45MwS7Mcs9wyQWkZ XfWbPhiL5d3fb1YlyA0k2hhs0ANerYrKpmCxKgDmUQUkgqm4gIBGF54PpWrQ+dJlZF+O 2TiA== 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=1dh6uGZ61Q7do467wqoDaMh6uB2u9srGrh1AVvKSU6M=; b=ksScAQO8KmzJZfgEpZgZRu0HxIoGHkUdfZPxcxtxImznuMmc10WiYf6m8SBLlbuO/k eMoMr++8g0I6NJ11NpGWm3b7k+QoBc/tJr/wsbbNw2/Y2AaI2Lp4C1AcRQwr8cY7NIqs pGsh00SMbBV+odCODumSXlJq7+/NiUPK4rhBoVXMp+rP9nfrWlXOktWgV0cb06JnJ5c0 Ch3r/qfO02jXELC/RVyDxcWRNPeKWMTsxUBrzf+NTH8ZggtcY9Vsmn0ooF+zRh6rkB0S 3SfQ3h8L56dTuBMr3dEDjvW+VqvfilNXv7o+J05ptB6DNg1NXtRhCz/ovphMX8iWQP+1 Mr2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=VtSYrdBh; 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 br12-20020a170906d14c00b008d14655248fsi1798643ejb.470.2023.03.01.07.25.01; Wed, 01 Mar 2023 07:25:24 -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=VtSYrdBh; 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 S230338AbjCAPW7 (ORCPT + 99 others); Wed, 1 Mar 2023 10:22:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbjCAPWt (ORCPT ); Wed, 1 Mar 2023 10:22:49 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCC3C410A4; Wed, 1 Mar 2023 07:22:47 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 6BDA560010; Wed, 1 Mar 2023 15:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1dh6uGZ61Q7do467wqoDaMh6uB2u9srGrh1AVvKSU6M=; b=VtSYrdBhwFAsMBULAFTYUYpOylcY4XED6Sw6J05beW6Q6pl0XGnYueudCn2JsgvgwiD7Bn J2vlIaTBeDzoBn73VzLTlszWkGkXD9XmvFTTj4cvyNOEmt769lODpdud+WqANq2iOt5Pkm kSZnQozL5PPeKmmUFm52qGZcR0M7cfXxSgwjY65axGIRxyZZziuL7dfjJ0DjJjxyGw/HHB OjGHqCGZPaloeHK5zTxGUBN5eZHFQDmZzJaPSadRdxcdTU8V9YppexKBcwNRQKLPRYtf+5 qyiCIR6wemROamDlR68biNhH2W3OsTU0hvxpbOetLMib/ZKxsGpWkPlBj//OwQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 4/8] nvmem: core: Fix error path ordering Date: Wed, 1 Mar 2023 16:22:35 +0100 Message-Id: <20230301152239.531194-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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 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?1759179518310720808?= X-GMAIL-MSGID: =?utf-8?q?1759179518310720808?= The layout is being retrieved before the addition of nvmem cells and after the creation of the sysfs entries. Soon the layout operation will have the possibility to fail, hence adding a new goto label in the error path. Before doing so, we need to fix the operation order in the error path. Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 56b4b20a95a9..16044377a41d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -975,9 +975,9 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); + nvmem_layout_put(nvmem->layout); if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); - nvmem_layout_put(nvmem->layout); err_put_device: put_device(&nvmem->dev); From patchwork Wed Mar 1 15:22:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62963 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3694079wrd; Wed, 1 Mar 2023 07:28:07 -0800 (PST) X-Google-Smtp-Source: AK7set/Y4GO6mqUnPyEVGWk0veebw2FPNXHKDC3DdaSo0cJfWXKZbPwaqi+db3+Dbb+GtBEXZPUg X-Received: by 2002:a17:906:6b91:b0:8b1:7e88:c20f with SMTP id l17-20020a1709066b9100b008b17e88c20fmr7666056ejr.15.1677684486776; Wed, 01 Mar 2023 07:28:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684486; cv=none; d=google.com; s=arc-20160816; b=LsD2MZXdMKqM/w3ebwZv4sbnuICvseNLiC+BNSy08EEaoGkX3BCjRsnxcFZaKzI4Io lnzPtNgxw05J3M8joMwLxZDjsnKo58ahrxhWDLbvIaH62JZ/dRyRa40i3JJCHwK9+yXg GhQ8jaE5e8366HX8nuNNo4O+CmqA5F7BjCBzVGOiq2NFONWBgpVhKr3gVZa3vRBtpjZv TYVz9Qd6N/d4CfJdu3AwFbHiJxacMJibq51E7717SilKge48qvp34yXUv0DJvUtY0j3F dNm+bQQZb84zrKo5dyt/h9RY9wa+ocp2AR4eCqD5v8PKxeCO+CdwaQrtPpZx6kGipxOF EYWA== 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=GuIzUxO4lQXjU9mkGsm3TUZaxNfzhaCKElzogF6isV0=; b=dHYmAGY4oZkFbDObi0/7zCE5ce/HicN9xWdPYVUF3Vs2wuYJ9nlE9I3D+OtJ11KvEC 1zTryHYRAMK1ZLPfY6fvnfRc5AxnrxCNnYIfPLrWpnk3GRDxIEG/gXjPp6f/ja2ztUPG 1PrmfcGIUgmvJUsh5hYlpz96QOswvmATzT6RZYJlF40haEWCuZLNK+1bShV3YTMLIaMF 9Np8Ot+KMo4lw+gkSy/TIt3g7c6dGj22rZofJy6/FcM3O7cwisLZTxQc3xubEEh9lchc YEsiyZLrgCCVQN/r5GntdMXRvzwsJBsWYsMEkKbhw/HuvaTi+9wfI/FrqLQkCU+vjVfv prqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=fMXMYqkW; 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 bl5-20020a170906c24500b008b8a4ed82fcsi15587720ejb.947.2023.03.01.07.27.37; Wed, 01 Mar 2023 07:28:06 -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=fMXMYqkW; 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 S230359AbjCAPXH (ORCPT + 99 others); Wed, 1 Mar 2023 10:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbjCAPWu (ORCPT ); Wed, 1 Mar 2023 10:22:50 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E649442BD9; Wed, 1 Mar 2023 07:22:48 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 9DD6960013; Wed, 1 Mar 2023 15:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GuIzUxO4lQXjU9mkGsm3TUZaxNfzhaCKElzogF6isV0=; b=fMXMYqkWJ3UjHLEh6WJlxZ/yVh1q0t2kjD0aviSY8eAz9MuvL53UfdXKX4S4xAwjSWfFNn sDrjZT/U5TPdJ7Eqc4rmRZiV8pM23fZbc4f2RY5cI59HOAp3BT7Psti1VTHB69Un/OKV+K DZE/pfCJLZMu/u7aKcd3Odj9nOZpNB/EPouA4si1lgYNw4M/JAi/MrmLmDHo69R3OA3Wcd O6a/tnNE0E7IoAB7wBhUX+uNvWDi12uTYaeKoc2kLL3cNxS4W2VmCO8TAng9J4+XFUEUkF VFwRQ0JVRVsFIKrDgcViHCC763rFlu06DgIttgms+3/LrHjGduUhjt/iFTwbQg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 5/8] nvmem: core: Handle the absence of expected layouts Date: Wed, 1 Mar 2023 16:22:36 +0100 Message-Id: <20230301152239.531194-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759179688447235358?= X-GMAIL-MSGID: =?utf-8?q?1759179688447235358?= 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 --- drivers/nvmem/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 16044377a41d..a66c37a03a36 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -762,7 +762,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { struct device_node *layout_np, *np = 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) @@ -944,6 +944,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) * pointer will be NULL and nvmem_layout_put() will be a noop. */ nvmem->layout = 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); @@ -976,6 +983,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); nvmem_layout_put(nvmem->layout); +err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: From patchwork Wed Mar 1 15:22:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62962 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3694040wrd; Wed, 1 Mar 2023 07:28:00 -0800 (PST) X-Google-Smtp-Source: AK7set8V+foWzeWIlqetSPIbOTOG+ekBZB9rN6yEn34Y/3vypo+JRdBF7TnOzdaE0eGyq/TSQWYb X-Received: by 2002:a17:907:6f11:b0:8b1:7de3:cfb4 with SMTP id sy17-20020a1709076f1100b008b17de3cfb4mr6998010ejc.4.1677684480759; Wed, 01 Mar 2023 07:28:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684480; cv=none; d=google.com; s=arc-20160816; b=s4skaYGsp0KKGsk3FXH66wHN15Tqp2/vP84FaCiyzO17hRU+rH/6fx4H0ZCWy0lJVC JUVduXa28ZB8z5vflNPlpxQ35PbVIsAj0K0C9utbGK7/9f4hsG2yZhQGta2iQCIlKza4 rTCnLSY8Hfnnh+SS1if50Qfzy0u54kgBpAv8gJPxYI+kV1AiHkwXonCsSxcSoG6ECZCN wDH/G1ZWbZe8lIOjDfJ4flMMexhHvGG1GiUO13Yj6/rGqiJ33eyA9c4MvXehCpxQ//Gb 5XmH9PknJSiEFoePnXksDjRqkmFbGPwBs4rI929HE+wA/ILgUnRnDgc81o2w4wsNTiwr RKZw== 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=veHqp22wWolx6RiZnbbvLOutWer672c27ajS/GJmogc=; b=tNlEeqDid1vlUXGBDBmQggXw4ODZQffntwEC6Ix1hUqRvuFsJEp8PLlDxX7/95rnhE dAQuCrI6cfsPFyJ+r9o9mS9ib/f4pGSq4FoLGmPwIeT6eTUjFDBqz9Aw3K9S40z4bl7S SGm6HBV6NGfXDV3sqjyz1IkFS7TPnnXHnGXolstBMOql7ygdS2LtjTNlSS6etFfk2rdG 3AwUZs14Krm/L9rG23WKPj4ppxHHw4y6WH+3fWk8RHzaStHxsQnWZlcrteHlCIe0/oL5 +zDVOOCLq7pxJF61kT41IFV96UvKzKkvmDBwxjEKCgqKgRjiUmWAhxeQ16VQasPxg/Dx vFlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=QVakPxE5; 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 gh12-20020a170906e08c00b008d28622c8dcsi824323ejb.566.2023.03.01.07.27.37; Wed, 01 Mar 2023 07:28:00 -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=QVakPxE5; 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 S230369AbjCAPXK (ORCPT + 99 others); Wed, 1 Mar 2023 10:23:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbjCAPWv (ORCPT ); Wed, 1 Mar 2023 10:22:51 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D69457FB; Wed, 1 Mar 2023 07:22:49 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id CAE8D60006; Wed, 1 Mar 2023 15:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684168; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=veHqp22wWolx6RiZnbbvLOutWer672c27ajS/GJmogc=; b=QVakPxE5LSVc9MxAkGBRSgmdbC2BCKTsWJTp+wDGqvTdkral5N3TNtKgiCFRSWhXG5WMjo y5voAUtX7dUaNEoz4+v3cznCrhhQUHj8r+Ed+5ErLy9xmAp1vlWxuXEhg04OX5ugK0GPyL 93jz84NT+MnJKYx0T9USiBDJoi7S4iw6u7cmM6iPY92N3I/kvUAGX1Y26ffb3X/Qgvl4mk BL1KrYcQhG+YUtNzK0hnsspmRuDzPDGIoxqb3wLc4zluZpbfKsjgRE5xRJjgfI/8p+w8hj ulvz8jQkBfFn67nqFORPXj3LqTsHOh7WddcKfqG3YTc1At9Sa30cswQW36Anpw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 6/8] nvmem: core: Request layout modules loading Date: Wed, 1 Mar 2023 16:22:37 +0100 Message-Id: <20230301152239.531194-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759179682338105805?= X-GMAIL-MSGID: =?utf-8?q?1759179682338105805?= 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 --- drivers/nvmem/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index a66c37a03a36..8e07b9df3221 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include struct nvmem_device { @@ -768,6 +769,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 Wed Mar 1 15:22:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 62960 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3693340wrd; Wed, 1 Mar 2023 07:26:45 -0800 (PST) X-Google-Smtp-Source: AK7set8XrODLnmeCgLy9fvSsoHumYJABvv/7kKCba1gH/vQevZOo0DxBoR6Vc0Tqikr+mTxzLwZ4 X-Received: by 2002:aa7:dd4d:0:b0:4af:515d:57ce with SMTP id o13-20020aa7dd4d000000b004af515d57cemr8340351edw.15.1677684404961; Wed, 01 Mar 2023 07:26:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684404; cv=none; d=google.com; s=arc-20160816; b=xtIskI8mjp+kt8ooiYUAhu1lkcXxKbvlpprQCmWrfIQqpm+w/F9iqB/a+Oy4sf53l5 VUdTzT0cMi2seMBC1IgNFquDnSWoXAtlmoOkSCIBpp/fsXceo8nY7GglyyGDhOuBZHBc /gOK80U6ClaGPjXMYOWZd4Mw18qSawQCKZRP165CvfqU3/SfH88c4L1DqkEq12icABQ4 gjkYucbHVTqgqtpVj+tQR1AMwP2XNUF6m7ptKmqtDKTEcGmV2WGB6/hiqOvtrm9YqaHv nHZPU33ze92J3hMpjr1pEVNNFCWiLG2Cf27CmSF2A4HTu63274pcWarpoRwxl1BgqwCg uqlA== 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=X48eOuQR9g5TMfWe2rTj2NLQ7Kg+37T7XdPWVVAdg/k=; b=jikPGh2PR5u8gvbEnCAhENQxm+TOddIcCDsIcJ1+qDpcFMB0WFYdRH1JM5kRUFfVs/ k33bxREO+WislExziYAk4/Q9tgwykAkEs4vsKYo89UO7PZa2EbLHckyw36cTFsvHjF3F yvjwMsZm5cdnea4HPHqKcpx5igbk6DC+FVz4eScx16XIWqnGHWl/sdmZAplg0R1mv2p4 b6VO1hOFquBzar3S+XzKxFcRD7t6ob6XeCkeTzLB6G8/aoP5/YOWwwWQv2vt/Z72yITe gCzmwma3UDOaFXHKAvHYMZL2moa4GuOQv+3g3baPZhEscBICtcAYQZVZM1Z+3mmD6TCL 4DXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=YvX0uQbY; 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 ca24-20020aa7cd78000000b004acc5bb3e0esi1981499edb.562.2023.03.01.07.26.22; Wed, 01 Mar 2023 07:26: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=YvX0uQbY; 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 S229879AbjCAPXV (ORCPT + 99 others); Wed, 1 Mar 2023 10:23:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230312AbjCAPWz (ORCPT ); Wed, 1 Mar 2023 10:22:55 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::223]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D4810DE; Wed, 1 Mar 2023 07:22:51 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id EE1226000F; Wed, 1 Mar 2023 15:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X48eOuQR9g5TMfWe2rTj2NLQ7Kg+37T7XdPWVVAdg/k=; b=YvX0uQbYrMLltUcObHa7M12j5xm3cWqbzZKlrX3RdCRhiXDscazjQPndiZTGwwtj2HcxgN b6n+ufqWUB2cDnewB0mCllYIBgQ+6/Q4/h3HFl0SLwtDT9Cf164VTEucnEP4dd7exyrS0P fdbA67QELtFZc0Gyorwu42Y1sc0UKehjAV3ET7mpmZSzyEYcQl+zH6biyPPJvnCRTxgZqx RVmXriiXlUYJHp8ejHFh631aSjV2DJ/MycrkvC+/3mSMbfqp0UBPKuL7z2ProgjOLUBNEM FMDVe4+404vvh5SE2TKmSzZqs0+oQeiQ9lrmcEpENBDmYfQoihfReuelBdKIKg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 7/8] nvmem: layouts: sl28vpd: Convert layout driver into a module Date: Wed, 1 Mar 2023 16:22:38 +0100 Message-Id: <20230301152239.531194-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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 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?1759179602646955483?= X-GMAIL-MSGID: =?utf-8?q?1759179602646955483?= The nvmem core has already been converted to accept layout drivers compiled as modules. So in order to make this change effective we need to convert this driver so it can also be compiled as a module. We then need to expose the match table, provide MODULE_* macros, use module_init/exit() instead of the early subsys_initcall() and of course update the Kconfig symbol type to tristate. Signed-off-by: Miquel Raynal --- drivers/nvmem/layouts/Kconfig | 2 +- drivers/nvmem/layouts/sl28vpd.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 9ad50474cb77..3f2d73282242 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -3,7 +3,7 @@ menu "Layout Types" config NVMEM_LAYOUT_SL28_VPD - bool "Kontron sl28 VPD layout support" + tristate "Kontron sl28 VPD layout support" select CRC8 help Say Y here if you want to support the VPD layout of the Kontron diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c index a36800f201a3..9370e41bad73 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -139,6 +139,7 @@ static const struct of_device_id sl28vpd_of_match_table[] = { { .compatible = "kontron,sl28-vpd" }, {}, }; +MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); struct nvmem_layout sl28vpd_layout = { .name = "sl28-vpd", @@ -150,4 +151,15 @@ static int __init sl28vpd_init(void) { return nvmem_layout_register(&sl28vpd_layout); } -subsys_initcall(sl28vpd_init); + +static void __exit sl28vpd_exit(void) +{ + nvmem_layout_unregister(&sl28vpd_layout); +} + +module_init(sl28vpd_init); +module_exit(sl28vpd_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Michael Walle "); +MODULE_DESCRIPTION("NVMEM layout driver for the VPD of Kontron sl28 boards"); From patchwork Wed Mar 1 15:22: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: 62961 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp3693403wrd; Wed, 1 Mar 2023 07:26:53 -0800 (PST) X-Google-Smtp-Source: AK7set9cngcZl9rT5g1XY2hW34k6ECbn8OUkiehKxD53hbV8LFfnqcxu55bYqa69i/z3AGwaIJYd X-Received: by 2002:a17:906:ccca:b0:8b1:7e1a:ef22 with SMTP id ot10-20020a170906ccca00b008b17e1aef22mr6491801ejb.45.1677684413068; Wed, 01 Mar 2023 07:26:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677684413; cv=none; d=google.com; s=arc-20160816; b=oOmHkTYBGZD1cmxc9yq6KWGe7C7VPv9xLlICdubPyScUn8cg8drPPryosTKIVzalHj 4JV1/p7MFS8SeS4eZAT13Bkphkk1SEc9JYsyvPGdv80iGlcUT1elKDIeToZDF6lhIc5H H3JsfolB3srQR9iYEU7t29OYfGhFM/IycHdlr9+DPVhO9Me7eOgmJFbe5h26Xguqbb+x oJNfGM8i+uLy95Ef2Kl61m83js0nT92UFKI9vPo1HhSEa1dBqm19PvxmrkP+zCrDf27k AcGpfzokTOFbHgBw01qvbkdv44b68wXDC7aUyIlNkofYM1R//dWQm8rjeRx3sHmGoJ8c l4YQ== 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=Q/yvRwDf0AdtbTrlrjDEi4BXF/Fzx1LyWUDN6tw49lM=; b=1BLqRoHNn7uyD/NWteEH6L3Zd2Mbk0yMQFQSASqNMUmKXopIwY2ts32mrZuBfip5NE SDXD7OkcwH8QqAwCEfRBXCJ/fsDuY8k7X0E2N57iZgwmozA9hc79GUkktBYvPL2xeV6a ex5onb5F9KmnpA9KV6rp0NHyyHqYd+HcN0++CPSLYvgohOdNadEXD5P2qGcWJpVFDNzi 4L6s4cUGCqx0wk4XU6i9A2mcNSLmtD+DZxTFUTfUg0iV+CBK0AfG2JP2x5G0Zjt8xVQR w0x/fRao3KuXw+8yGgErPmOq3/L16JMe+DIeBqUXCm2yGcsRcgGq62uIqRI6Kd4rQnld DabQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="QaO/w24J"; 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 r14-20020aa7cfce000000b004beb39bf058si593232edy.83.2023.03.01.07.26.30; Wed, 01 Mar 2023 07:26:53 -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="QaO/w24J"; 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 S230380AbjCAPXZ (ORCPT + 99 others); Wed, 1 Mar 2023 10:23:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230330AbjCAPW4 (ORCPT ); Wed, 1 Mar 2023 10:22:56 -0500 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CE761BA; Wed, 1 Mar 2023 07:22:52 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 3F1476000E; Wed, 1 Mar 2023 15:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1677684171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q/yvRwDf0AdtbTrlrjDEi4BXF/Fzx1LyWUDN6tw49lM=; b=QaO/w24JvA08uvMecfKs3r8CgraP6VjdyZkEd/5pug68+pTJmHBixd1HJCmMo85/zrv3bn 56M8cs3BeKlGKeLmp1uYGwwGSEDlr8IoNrVry0MpPTXW0lUNAm7pF0wEUrO/l8mbnDPhG9 S5lj3Q4dae8TjES7TMFm1P9IPjQIBqwJxo7jWBbL8sI6PAP8LUgd0oJ0fN3gIzLRORP5Ts JwITliC2/ZSI0S3UwCttilFc3fzJKMQiaAX3wu/IuvhiJAuAh/2nf3LkY70bgFh7OE9sHA wISD71WHqi/EZyx+EMDKv6oKIUlu8lAfukcjNFr7n+/NL+EAbslHgeNSnjjT1Q== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , devicetree@vger.kernel.org, Rob Herring , Frank Rowand , Robert Marko , Luka Perkov , Thomas Petazzoni , rafal@milecki.pl, Miquel Raynal Subject: [PATCH 8/8] nvmem: layouts: onie-tlv: Convert layout driver into a module Date: Wed, 1 Mar 2023 16:22:39 +0100 Message-Id: <20230301152239.531194-9-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301152239.531194-1-miquel.raynal@bootlin.com> References: <20230301152239.531194-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759179611372156489?= X-GMAIL-MSGID: =?utf-8?q?1759179611372156489?= The nvmem core has already been converted to accept layout drivers compiled as modules. So in order to make this change effective we need to convert this driver so it can also be compiled as a module. We then need to expose the match table, provide MODULE_* macros, use module_init/exit() instead of the early subsys_initcall() and of course update the Kconfig symbol type to tristate. Signed-off-by: Miquel Raynal --- drivers/nvmem/layouts/Kconfig | 2 +- drivers/nvmem/layouts/onie-tlv.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 3f2d73282242..7ff1ee1c1f05 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -12,7 +12,7 @@ config NVMEM_LAYOUT_SL28_VPD If unsure, say N. config NVMEM_LAYOUT_ONIE_TLV - bool "ONIE tlv support" + tristate "ONIE tlv support" select CRC32 help Say Y here if you want to support the Open Compute Project ONIE diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c index 767f39fff717..d45b7301a69d 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -230,6 +230,7 @@ static const struct of_device_id onie_tlv_of_match_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", @@ -241,4 +242,16 @@ static int __init onie_tlv_init(void) { return nvmem_layout_register(&onie_tlv_layout); } -subsys_initcall(onie_tlv_init); + +static void __exit onie_tlv_exit(void) +{ + nvmem_layout_unregister(&onie_tlv_layout); +} + +module_init(onie_tlv_init); +module_exit(onie_tlv_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Miquel Raynal "); +MODULE_DESCRIPTION("NVMEM layout driver for Onie TLV table parsing"); +MODULE_ALIAS("NVMEM layout driver for Onie TLV table parsing");