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,