From patchwork Wed Mar 8 15:31:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp406885wrd; Wed, 8 Mar 2023 07:41:14 -0800 (PST) X-Google-Smtp-Source: AK7set+LphytE0cwIQ8RvIJxNCoW2Q1XhZGCrcSKJ0iaFj/JNfJCtqAdP7AdPRUn4ZJRfO3XX1Fo X-Received: by 2002:a05:6a00:4a:b0:5a7:6ee6:66f9 with SMTP id i10-20020a056a00004a00b005a76ee666f9mr16173434pfk.19.1678290074139; Wed, 08 Mar 2023 07:41:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678290074; cv=none; d=google.com; s=arc-20160816; b=p/zxv32NIq6G4lfOhu4ix7NMYzll7uLgoTgifiifdwY8/4i9zRuRIUvm2pG0KmCvl9 6jjY3wY9gAQRemUE41VFWJ6klb2NNGA8EYxsaYBxNvHzRGM6Gj5iR+wKwm8BWsp6X7fO N5nd4kr+scY4WgPqC0qvK6u+Bvxl7Wgd129YijGQn4Nk8OhSylY3a1ynZEz23wHJjJZX 1oXMdRnBAX54Zm2KicIkf8mKpSGmo+ir54jPnaYSGHCOyPD5z9q9FtoBB/+YF4AW95LR NkDZPLEbZO3J7/GyxTWeSaxVPbpANxfPizIhXDT0xyYDohaNXgb0q9VUuNYq3bSBwwx8 Ns/w== 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=Qi5NJbrismetNR4VDnzqWtfOpjOiDr0LEcWi51muTR4=; b=u0PwyjC+siJcNOgvKfOGXd5T6gtlspy+Sa7TTI1DVom0/PRZ7soyPgJXQAQhWqEqmm BIF0LTgQMtbjf84TpVkxb5WFDLc8h9IueGpwPnS2WTkiSzb3RGRQWsYOsTY2fvMWqOPm Bp1mwV77UdL+KRP/PB7yNUVcdQD3wNaVVi2IWY46QRf8dR9ttZ0x6+jbaHGlRMSC/NFf 5sViYu88o2cGfaKMj9aikDbj52rMNOTHdIYxLfwY5mqWvXqe61aWdmg4P1HRSSO+i7vr kLhM0VcfFBOlnOPTqtGqjxfLvNxEcdg3Rsa8CK//HDxTIEbDyt2SmmqtsL4WlPC1yZwe FEjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Riju3GbA; 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 k13-20020aa79d0d000000b005a91f5ed6b2si12526447pfp.147.2023.03.08.07.41.00; Wed, 08 Mar 2023 07:41:14 -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=Riju3GbA; 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 S232155AbjCHPc0 (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231816AbjCHPcU (ORCPT ); Wed, 8 Mar 2023 10:32:20 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FB03D5A68; Wed, 8 Mar 2023 07:32:11 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 505FDFF816; Wed, 8 Mar 2023 15:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289530; 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=Qi5NJbrismetNR4VDnzqWtfOpjOiDr0LEcWi51muTR4=; b=Riju3GbA5tXdErg/6M2b21kX9z8p23mbQF+XZ8vMJMFDtxac8NmHofRTkAyRm16KCnElFH paRLZ6veJY2ZcijqgBW8k3nl0T6PlF2ZTmwFraJ7BQwrX3Vt0ADPeso4vgy9ELYhaU9zgB YzXmZ9v0qF8Q4h84Re8OkhUIy4dXSTlrZ/Cy4b9Qpumsyrp5lvbnE9CjiwHfRTyrw9wpcD TYQOeAIyl1M3RXgmuODOSEAT8Qk9NDaiTHMddV8Yel0ekm6YC/Y/JkRjMDOR4x8gKaWjxa jvHs+VhlQtK0/WsfCggDp2JW4P1bZBDSZ88JM5N+t1Np3DIV+r3ZaETRsaMnGg== 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 , "Rafael J . Wysocki" , Len Brown , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sebastian Reichel , Wolfram Sang , Mark Brown , Rob Herring Subject: [PATCH v3 03/20] of: Rename of_modalias_node() Date: Wed, 8 Mar 2023 16:31:43 +0100 Message-Id: <20230308153200.682248-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-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_H2,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?1759814693110343175?= X-GMAIL-MSGID: =?utf-8?q?1759814693110343175?= This helper does not produce a real modalias, but tries to get the "product" compatible part of the "vendor,product" compatibles only. It is far from creating a purely useful modalias string and does not seem to be used like that directly anyway, so let's try to give this helper a more meaningful name before moving there a real modalias helper (already existing under of/device.c). Also update the various documentations to refer to the strings as "aliases" rather than "modaliases" which has a real meaning in the Linux kernel. There is no functional change. Cc: Rafael J. Wysocki Cc: Len Brown Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: Sebastian Reichel Cc: Wolfram Sang Cc: Mark Brown Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring Acked-by: Mark Brown --- drivers/acpi/bus.c | 7 ++++--- drivers/gpu/drm/drm_mipi_dsi.c | 2 +- drivers/hsi/hsi_core.c | 2 +- drivers/i2c/busses/i2c-powermac.c | 2 +- drivers/i2c/i2c-core-of.c | 2 +- drivers/of/base.c | 18 +++++++++++------- drivers/spi/spi.c | 4 ++-- include/linux/of.h | 3 ++- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 9531dd0fef50..fc74c786a867 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -817,9 +817,10 @@ static bool acpi_of_modalias(struct acpi_device *adev, * @modalias: Pointer to buffer that modalias value will be copied into * @len: Length of modalias buffer * - * This is a counterpart of of_modalias_node() for struct acpi_device objects. - * If there is a compatible string for @adev, it will be copied to @modalias - * with the vendor prefix stripped; otherwise, @default_id will be used. + * This is a counterpart of of_alias_from_compatible() for struct acpi_device + * objects. If there is a compatible string for @adev, it will be copied to + * @modalias with the vendor prefix stripped; otherwise, @default_id will be + * used. */ void acpi_set_modalias(struct acpi_device *adev, const char *default_id, char *modalias, size_t len) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index b41aaf2bb9f1..b62f5e4425f4 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -160,7 +160,7 @@ of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node) int ret; u32 reg; - if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) { + if (of_alias_from_compatible(node, info.type, sizeof(info.type)) < 0) { drm_err(host, "modalias failure on %pOF\n", node); return ERR_PTR(-EINVAL); } diff --git a/drivers/hsi/hsi_core.c b/drivers/hsi/hsi_core.c index 8fda8f1d064d..acbf82f755a8 100644 --- a/drivers/hsi/hsi_core.c +++ b/drivers/hsi/hsi_core.c @@ -207,7 +207,7 @@ static void hsi_add_client_from_dt(struct hsi_port *port, if (!cl) return; - err = of_modalias_node(client, name, sizeof(name)); + err = of_alias_from_compatible(client, name, sizeof(name)); if (err) goto err; diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c index 2e74747eec9c..ec706a3aba26 100644 --- a/drivers/i2c/busses/i2c-powermac.c +++ b/drivers/i2c/busses/i2c-powermac.c @@ -284,7 +284,7 @@ static bool i2c_powermac_get_type(struct i2c_adapter *adap, */ /* First try proper modalias */ - if (of_modalias_node(node, tmp, sizeof(tmp)) >= 0) { + if (of_alias_from_compatible(node, tmp, sizeof(tmp)) >= 0) { snprintf(type, type_size, "MAC,%s", tmp); return true; } diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index bce6b796e04c..8941a30574e3 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c @@ -27,7 +27,7 @@ int of_i2c_get_board_info(struct device *dev, struct device_node *node, memset(info, 0, sizeof(*info)); - if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) { + if (of_alias_from_compatible(node, info->type, sizeof(info->type)) < 0) { dev_err(dev, "of_i2c: modalias failure on %pOF\n", node); return -EINVAL; } diff --git a/drivers/of/base.c b/drivers/of/base.c index ac6fde53342f..3c1badab287f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1208,19 +1208,23 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from, EXPORT_SYMBOL(of_find_matching_node_and_match); /** - * of_modalias_node - Lookup appropriate modalias for a device node + * of_alias_from_compatible - Lookup appropriate alias for a device node + * depending on compatible * @node: pointer to a device tree node - * @modalias: Pointer to buffer that modalias value will be copied into - * @len: Length of modalias value + * @modalias: Pointer to buffer that alias value will be copied into + * @len: Length of alias value * * Based on the value of the compatible property, this routine will attempt - * to choose an appropriate modalias value for a particular device tree node. + * to choose an appropriate alias value for a particular device tree node. * It does this by stripping the manufacturer prefix (as delimited by a ',') * from the first entry in the compatible list property. * + * Note: The matching on just the "product" side of the compatible is a relic + * from I2C and SPI. Please do not add any new user. + * * Return: This routine returns 0 on success, <0 on failure. */ -int of_modalias_node(struct device_node *node, char *modalias, int len) +int of_alias_from_compatible(const struct device_node *node, char *alias, int len) { const char *compatible, *p; int cplen; @@ -1229,10 +1233,10 @@ int of_modalias_node(struct device_node *node, char *modalias, int len) if (!compatible || strlen(compatible) > cplen) return -ENODEV; p = strchr(compatible, ','); - strscpy(modalias, p ? p + 1 : compatible, len); + strscpy(alias, p ? p + 1 : compatible, len); return 0; } -EXPORT_SYMBOL_GPL(of_modalias_node); +EXPORT_SYMBOL_GPL(of_alias_from_compatible); /** * of_find_node_by_phandle - Find a node given a phandle diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 44b85a8d47f1..3bbdc5fe3b99 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2354,8 +2354,8 @@ of_register_spi_device(struct spi_controller *ctlr, struct device_node *nc) } /* Select device driver */ - rc = of_modalias_node(nc, spi->modalias, - sizeof(spi->modalias)); + rc = of_alias_from_compatible(nc, spi->modalias, + sizeof(spi->modalias)); if (rc < 0) { dev_err(&ctlr->dev, "cannot find modalias for %pOF\n", nc); goto err_out; diff --git a/include/linux/of.h b/include/linux/of.h index 0af611307db2..b1eea8569043 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -373,7 +373,8 @@ extern int of_n_addr_cells(struct device_node *np); extern int of_n_size_cells(struct device_node *np); extern const struct of_device_id *of_match_node( const struct of_device_id *matches, const struct device_node *node); -extern int of_modalias_node(struct device_node *node, char *modalias, int len); +extern int of_alias_from_compatible(const struct device_node *node, char *alias, + int len); extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args); extern int __of_parse_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name, int cell_count,