From patchwork Wed May 10 15:48:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 92196 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3739094vqo; Wed, 10 May 2023 09:07:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4HJZERhGwA2f84A7c9j2NmEbw85wvluCJo6o/WHXyx+WdihV4+kitjLc5WAyibZpSB791s X-Received: by 2002:a05:6870:956a:b0:187:8260:2f8 with SMTP id v42-20020a056870956a00b00187826002f8mr9758521oal.6.1683734840491; Wed, 10 May 2023 09:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683734840; cv=none; d=google.com; s=arc-20160816; b=ygh544P/HlakWnMLiCXDN/YhmfbqSCQMEqEKCqbFUKYkseiNrsBaM4UAddZGF2fjfW J2j9f5455FK4hJXMPgQcOjw56Cwm7vOb7m1z/fTMsD54NK8HBFEUlo8cry66aIxiE6xC TkFTqOUUbRC/px7WuoSdjbkA+MZksmSCtcHTw5o4mF4V7tO9sbovQoMyzPOuHBdU6cbt zoWbmR39HFYF25amNeOvi+7fG2f5Tq+7yrO1T2iEERdlVamzC62uZrXiu++UcnHklloi 3V02ZcIXhFgWZNQ2A8IwzzxsRgWweAb4XR9ZVvkvK4BP3vvFCGFIfafcZpTBCsP77Kxu yChQ== 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=eTzUAUn2/6zCa90roD3BEhvCRbYoR3aMy4PUneIBrPM=; b=KGkBAR24fRHCSobE82+Gm1xRMSOvkWA4ZP1FF3fzvs6Pibr60Bz3sk/6nUev09u2yY lhOU6LoOcuGQ5S5LTnsvFi/fwlWRJdvUSxnDyiuUVOa0eatK9DkZcMr+hKnjLLZwqD+u +H/L2QGIAmv6+t/o9CerayyNoKAgKNlqw5x6eXbcaJ+6rfE+DFJCbmC+O8p9ULRQT4Vc MV7fDQu3/3dPjth8MgbnUwRHEauC5q4I8CyoyMCqWaMwpMsFwJ1eLyW6nJMbhfQebX9+ LF6sRHy4AJDdf4rZ1+16HF00wDRMad9BLmZ+rUo6rVXRYP+ZRORE98O/P8AHh8zXm65A rBmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UkiDwJ6P; 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 n13-20020a056870970d00b0018f57b99467si9675549oaq.288.2023.05.10.09.07.02; Wed, 10 May 2023 09:07:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UkiDwJ6P; 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 S237631AbjEJPsY (ORCPT + 99 others); Wed, 10 May 2023 11:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237365AbjEJPsL (ORCPT ); Wed, 10 May 2023 11:48:11 -0400 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 149DD1BCB; Wed, 10 May 2023 08:48:08 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id A716FC0004; Wed, 10 May 2023 15:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1683733687; 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=eTzUAUn2/6zCa90roD3BEhvCRbYoR3aMy4PUneIBrPM=; b=UkiDwJ6PmmRH+dllni1nZppCO1kMi1iL8f0YSzz6HMHb6cDJPNmwTh8WsvIlDrbl1Ewpml JhgPduur1oojt7UZEDpsmRFpFSpSvpaIWASDDMJ5Ve+FT7l/C3A+se09IfN+emu6+OUdLi mZyQQ9NdIIYgn+zM3RQqh2WdLt9pnConqmEEEgHJKM1WxXbbl02tV2LlWxw+lWD8ETYa4Y rJjaHH7kho1KvYF9c9N1qMAtbWb7RP4uHWKLD8DsyfQuKYcJIJms84KTwMLlvgIHAdKeMM KDYkX8tZWSOsfDnSEnL3JVMw6pwKGJelLceNIYpxYqFT9kMWwX3JbWfPl9m3aw== From: Miquel Raynal To: Rob Herring Cc: Frank Rowand , Thomas Petazzoni , devicetree@vger.kernel.org, , linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org, Thierry Reding , David Airlie , Daniel Vetter , Mikko Perttunen , Miquel Raynal Subject: [PATCH 3/5] of: module: Mutate of_device_uevent_modalias() into two helpers Date: Wed, 10 May 2023 17:48:01 +0200 Message-Id: <20230510154803.189096-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230510154803.189096-1-miquel.raynal@bootlin.com> References: <20230510154803.189096-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,T_SCC_BODY_TEXT_LINE,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?1765523944004030060?= X-GMAIL-MSGID: =?utf-8?q?1765523944004030060?= Let's move the logic of the former helper into module.c and use it from an inline helper located under of_device.c. This way there is no change for users while the logic gets moved to an OF-only file. Signed-off-by: Miquel Raynal --- drivers/of/device.c | 23 ----------------------- drivers/of/module.c | 21 +++++++++++++++++++++ include/linux/of.h | 7 +++++++ include/linux/of_device.h | 9 ++++++++- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 5e538e1ed623..7909eefc650e 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -245,26 +245,3 @@ const void *of_device_get_match_data(const struct device *dev) return match->data; } EXPORT_SYMBOL(of_device_get_match_data); - -int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *env) -{ - int sl; - - if ((!dev) || (!dev->of_node) || dev->of_node_reused) - return -ENODEV; - - /* Devicetree modalias is tricky, we add it in 2 steps */ - if (add_uevent_var(env, "MODALIAS=")) - return -ENOMEM; - - sl = of_modalias(dev->of_node, &env->buf[env->buflen-1], - sizeof(env->buf) - env->buflen); - if (sl < 0) - return sl; - if (sl >= (sizeof(env->buf) - env->buflen)) - return -ENOMEM; - env->buflen += sl; - - return 0; -} -EXPORT_SYMBOL_GPL(of_device_uevent_modalias); diff --git a/drivers/of/module.c b/drivers/of/module.c index c729675fdd04..874f3fb8220f 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -132,3 +132,24 @@ int of_uevent(struct device_node *np, struct kobj_uevent_env *env) return 0; } + +int of_uevent_modalias(const struct device_node *np, struct kobj_uevent_env *env) +{ + int sl; + + if (!np) + return -ENODEV; + + /* Devicetree modalias is tricky, we add it in 2 steps */ + if (add_uevent_var(env, "MODALIAS=")) + return -ENOMEM; + + sl = of_modalias(np, &env->buf[env->buflen-1], + sizeof(env->buf) - env->buflen); + if (sl >= (sizeof(env->buf) - env->buflen)) + return -ENOMEM; + env->buflen += sl; + + return 0; +} +EXPORT_SYMBOL_GPL(of_uevent_modalias); diff --git a/include/linux/of.h b/include/linux/of.h index d99f33fc25d3..203bd2895d94 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -389,6 +389,7 @@ extern ssize_t of_printable_modalias(const struct device_node *np, char *str, ssize_t len); extern int of_request_module(const struct device_node *np); extern int of_uevent(struct device_node *np, struct kobj_uevent_env *env); +extern int of_uevent_modalias(const struct device_node *np, struct kobj_uevent_env *env); /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, @@ -777,6 +778,12 @@ static inline int of_uevent(struct device_node *np, struct kobj_uevent_env *env) return -ENODEV; } +static inline int of_uevent_modalias(const struct device_node *np, + struct kobj_uevent_env *env) +{ + return -ENODEV; +} + static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, const char *list_name, diff --git a/include/linux/of_device.h b/include/linux/of_device.h index af5ee78e0c05..5e428bcf3d63 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -44,7 +44,14 @@ static inline int of_device_uevent(const struct device *dev, return of_uevent(dev->of_node, env); } -extern int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *env); +static inline int of_device_uevent_modalias(const struct device *dev, + struct kobj_uevent_env *env) +{ + if (!dev || !dev->of_node || dev->of_node_reused) + return -ENODEV; + + return of_uevent_modalias(dev->of_node, env); +} int of_dma_configure_id(struct device *dev, struct device_node *np,