From patchwork Wed May 10 15:48:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 92194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3738597vqo; Wed, 10 May 2023 09:06:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BOWNoa0E8Iq3k+/42/GDl5cBlLc//G8AajTF4FB2ctVuD4cJC2nmzZR5atuGkd8P3MOMf X-Received: by 2002:a05:6808:2b09:b0:394:1ffd:463e with SMTP id fe9-20020a0568082b0900b003941ffd463emr2167341oib.25.1683734809143; Wed, 10 May 2023 09:06:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683734809; cv=none; d=google.com; s=arc-20160816; b=jkoxluqPSN0qNGCudBGfcoWE4G3LUMjNpRVKkCA08zUqKidvllySOnDcKkq7hL3+f5 GaLJ9DEqEu7UCXCgJtT0expwRw9IwEfQatDE5P2azcrmDdLQRPoqbnt2Ll1RtIjPFv1C dr6sRAVzJ09Q13nG6mkQwUCUwYLXGjDUG+1r6MfjiiZX21JcOep8JKD6pEScqpQvj9LN RJXh9xIoev9Qw/ckvnCcQwaQTNuWTQKHbYwQZ1uKjW/+yvBT3CWYTAEqXkSppytmwGQJ jXbXRSQihRiNfd5sULD3xIFUDSTFuYrhYoVYn99EysOSyEEOLfCCZK1XlzSzh3Miai8S av9A== 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=F/KSDSRKpLHcB4gpgTZNIsinLN/YQM+hIOrBqkC1k88=; b=szCnaNVBO9of2tj9djshPSXx0RjMNxFfVNbiswvY+rRefTAUvzmtGq7yocsldjnlcw EAJQVALhHAeFG/Syco6pLXJHsEfj8VS1m2qW3taxVn4/3AUv0Jowpqzcyw/Yi4BxJn5r h9VjWxsXp++shZ3p7J1aPWO6sc2zu5pD0MWbK0FNClFdL3+ap3/Q4gx/SIKWURzRFp2e UcxzE1v4zHd4rV5JRLbYh+8Wv5Waio9KfMwaqx2DwN5BkWQjP44QJvaDjIlRBn6AtCoJ GMckfpBiOaBnNsTXCX37FK+tyJxG+FVyIg7xjH58gOjDR4Uc1xUoxsBksq7FBbzOtgPZ m6wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UyBOIGVD; 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 r128-20020acac186000000b0038e6978beb7si2986676oif.274.2023.05.10.09.06.14; Wed, 10 May 2023 09:06:49 -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=UyBOIGVD; 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 S237560AbjEJPsT (ORCPT + 99 others); Wed, 10 May 2023 11:48:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237320AbjEJPsJ (ORCPT ); Wed, 10 May 2023 11:48:09 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D5C10FA; Wed, 10 May 2023 08:48:07 -0700 (PDT) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 90E59C0005; Wed, 10 May 2023 15:48:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1683733686; 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=F/KSDSRKpLHcB4gpgTZNIsinLN/YQM+hIOrBqkC1k88=; b=UyBOIGVDHTkQ8GTasBO0HB+J1Z++0S2Zw1KtqqxmwJ4aGo1ar2Fehj+YzqCd6nS9aiJGk/ QOiyr4fDBL+t9ntTKIlFiCOfk00S5AjWG/encJ5YI4PUdlSKCTOi15hO6HQjCB5SuTe7Lh HQsVgBhuEYVlvDsCJN2/yLuATuL7TI7gSsZo0nBDvUt0hcSkxvutbWZGDPoR8sYKECBzoi PhppTuKWj0NcjNng2XItbbpsvkn1N3dXJ367S0donGgt2cQYM3f25bYfyqKFgLGxyNgUY9 K9+1jyBXd2FOVnxVI2K6WYNswx6HUfUCQK8VyM62nc8x9N0nFQ9ABQ9+Y46jlw== 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 2/5] of: module: Mutate of_device_uevent() into two helpers Date: Wed, 10 May 2023 17:48:00 +0200 Message-Id: <20230510154803.189096-3-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?1765523911613877159?= X-GMAIL-MSGID: =?utf-8?q?1765523911613877159?= Move the OF related logic inside of/module.c and use it from of_device.h with an inline helper so there is no visible change from the users point of view. Signed-off-by: Miquel Raynal --- drivers/of/device.c | 42 --------------------------------------- drivers/of/module.c | 41 ++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 6 ++++++ include/linux/of_device.h | 17 +++++++++++++--- 4 files changed, 61 insertions(+), 45 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 45ce83a8945f..5e538e1ed623 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -246,48 +246,6 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -/** - * of_device_uevent - Display OF related uevent information - * @dev: Device to display the uevent information for - * @env: Kernel object's userspace event reference to fill up - */ -void of_device_uevent(const struct device *dev, struct kobj_uevent_env *env) -{ - const char *compat, *type; - struct alias_prop *app; - struct property *p; - int seen = 0; - - if ((!dev) || (!dev->of_node)) - return; - - add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node); - add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node); - type = of_node_get_device_type(dev->of_node); - if (type) - add_uevent_var(env, "OF_TYPE=%s", type); - - /* Since the compatible field can contain pretty much anything - * it's not really legal to split it out with commas. We split it - * up using a number of environment variables instead. */ - of_property_for_each_string(dev->of_node, "compatible", p, compat) { - add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat); - seen++; - } - add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen); - - seen = 0; - mutex_lock(&of_mutex); - list_for_each_entry(app, &aliases_lookup, link) { - if (dev->of_node == app->np) { - add_uevent_var(env, "OF_ALIAS_%d=%s", seen, - app->alias); - seen++; - } - } - mutex_unlock(&of_mutex); -} - int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *env) { int sl; diff --git a/drivers/of/module.c b/drivers/of/module.c index c05fb8ca575c..c729675fdd04 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -8,6 +8,8 @@ #include #include +#include "of_private.h" + ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) { const char *compat; @@ -91,3 +93,42 @@ int of_request_module(const struct device_node *np) return ret; } EXPORT_SYMBOL_GPL(of_request_module); + +int of_uevent(struct device_node *np, struct kobj_uevent_env *env) +{ + const char *compat, *type; + struct alias_prop *app; + struct property *p; + int seen = 0; + + if (!np) + return -ENODEV; + + add_uevent_var(env, "OF_NAME=%pOFn", np); + add_uevent_var(env, "OF_FULLNAME=%pOF", np); + type = of_node_get_device_type(np); + if (type) + add_uevent_var(env, "OF_TYPE=%s", type); + + /* Since the compatible field can contain pretty much anything + * it's not really legal to split it out with commas. We split it + * up using a number of environment variables instead. */ + of_property_for_each_string(np, "compatible", p, compat) { + add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat); + seen++; + } + add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen); + + seen = 0; + mutex_lock(&of_mutex); + list_for_each_entry(app, &aliases_lookup, link) { + if (np == app->np) { + add_uevent_var(env, "OF_ALIAS_%d=%s", seen, + app->alias); + seen++; + } + } + mutex_unlock(&of_mutex); + + return 0; +} diff --git a/include/linux/of.h b/include/linux/of.h index dcdd9396ac37..d99f33fc25d3 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -388,6 +388,7 @@ extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) 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); /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, @@ -771,6 +772,11 @@ static inline int of_request_module(const struct device_node *np) return -ENODEV; } +static inline int of_uevent(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 bca66f59814a..af5ee78e0c05 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -35,7 +35,15 @@ static inline ssize_t of_device_modalias(struct device *dev, char *str, return of_printable_modalias(dev->of_node, str, len); } -extern void of_device_uevent(const struct device *dev, struct kobj_uevent_env *env); +static inline int of_device_uevent(const struct device *dev, + struct kobj_uevent_env *env) +{ + if (!dev || !dev->of_node) + return -ENODEV; + + return of_uevent(dev->of_node, env); +} + extern int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *env); int of_dma_configure_id(struct device *dev, @@ -55,8 +63,11 @@ static inline int of_driver_match_device(struct device *dev, return 0; } -static inline void of_device_uevent(const struct device *dev, - struct kobj_uevent_env *env) { } +static inline int of_device_uevent(const struct device *dev, + struct kobj_uevent_env *env) +{ + return -ENODEV; +} static inline ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len)