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;