Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1816179lqm; Fri, 3 May 2024 07:23:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvfDou9Yy8vCN4mIglXgD/+8K27V54c4aFH14zVHhEMGCmp7EeS2YV7/HfYK6gtWlEl5dgldKE+C2r3tV6O6g6OPF+4rRTZ/nxV4beCg== X-Google-Smtp-Source: AGHT+IGykG1GlfoMlx7FHsrMojDA8vXF27xQx0nse/aRlmrRat+kofx2qlP0xEkyNGXwfKqftW3L X-Received: by 2002:a05:622a:1315:b0:43a:db76:3884 with SMTP id v21-20020a05622a131500b0043adb763884mr2872512qtk.68.1714746198500; Fri, 03 May 2024 07:23:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714746198; cv=pass; d=google.com; s=arc-20160816; b=FfyKDcWp5AEsJJZSLqYWRXklNXT3GU3fTIf0ZlETMUwTu7ES+4KHCdwKXU3GLZgWEd B5CG8WOrWaXfL61adHFj6ajvSEzpEHfzRrwJxmh1mYyIiS/vxPxvLw4VbmpJafODpxPK SDcAbYD7r+Ca8/Tx69B424yn2fNvExefTs3dUQ7y9D7V07/f3dKaYDhRAf+KmU2CFWGy 5J+kE2/C8n0AIf8wBOG+6MMyoWynV7fFv+IUYKFBssboPY8O4FM3GvE/COQ+fHCeD+gW VeWLMd5Aqe81sf7S9v5SrkXK4qU37ua1et25udJZ2EWGOyiKP1VoM3icthv2K9647Lvx 334Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=VhCxOhm2wL8IBQ2UHqwouQlBmqxgQGndTJ7ExI+Ljes=; fh=FM+ryhC3zZYH/pBRXfFNqQ7rqZR5mg7STLNv34C2ANM=; b=s5QAO6J9N76jtfTFObbzlHwrdBKCbgvJBsCAfGVMeGncNsosw33zesyIEj8lQntOdJ B9nmf9BDmJCd1n8ZBex2pXvy+Ev958yNEBOHn0rKDAlur7uauJp5Kl9pUQmJiiik9brm 2yrC/ln1Mmw833gw3lv/PX7b2b68lR8I7+mtS2kaxtUmkoAaReNqJqG9JD2aGYZ4zt/s YgIq7UsCq2HsUg+l+sGEDzKUXldP0Zb5iZ6XTLFPZYjI0gRXP01XcYjSHsDHJ4PsF252 /QdYsRZhfCIMQdBVq0ufUJnZNQN/9X7KqoNKsiIhxoxaY9fSFXbKqWzqFUMFVIeYetjz AElA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=KSyGTDk2; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-167765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d4-20020ac85ac4000000b0043aab3d8a94si3532387qtd.415.2024.05.03.07.23.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 07:23:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=KSyGTDk2; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-167765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2237F1C2160B for ; Fri, 3 May 2024 14:23:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8EF0C156C4D; Fri, 3 May 2024 14:21:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="KSyGTDk2" Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 922321552FC; Fri, 3 May 2024 14:21:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714746083; cv=none; b=BJYhbm3xxXYKj5N79zhY2s+WE05F7zkzSnuHhmvx3UdQ9LFyd1N/mZzyWwI1El7lk9/Nz/0ux0McucxKOYCS2oIAj56KxtAwnCmLnnppZNMmEyXJSVjmFNm2KY+P/Esz+ZVV6ZT7HL7VQmyx9WQpNJ5dVhTDY42gb2v6iS5tR5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714746083; c=relaxed/simple; bh=3/3CibSLjnE7Z2tUb3XhZmdn0m09V6Wb8mUSh7tSTtg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YhmedSHXaWIqad6AtFoXfWZXv0kunjqgdCuistV9syvh85oLhcQmFqYWZnjFY5GBAqB1RtKfDwDrgG4Ysjtv2m8R/mh/iszXt/6xQKbuez9tNEATsFxa39cXLh6pcJC8QQtG+x6+4YnxomjSqfffc+b1lWCZNGTz/aiAnIvhdaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=KSyGTDk2; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 00C5EE0007; Fri, 3 May 2024 14:21:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1714746072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VhCxOhm2wL8IBQ2UHqwouQlBmqxgQGndTJ7ExI+Ljes=; b=KSyGTDk2Ze0sA+Xr3CMjqq69hhUODAFh7KrVLI+BwthMp0mz9iItW7Evzw5ZfJRoNcoPnU OeNuNt4VaIb6OVgVFH4ElemZuPFdg4lf58kozOqEyZl4usKuKbzmxzPHx90DqNSc3H6Xak 2sDh76IWcOqKMZ4d44pza9aTR09/dKBYlK3r17iGq/ONpRqfBQRyzMy7h8Y+NpKoex1NG4 IlABmkbPIi2DrZjTwA0f2A7kGCupj/i0YDBQ4zaSW3gnbfMS8mB+WZQrdw23B6jItCHDCV 4mYAtOpSZJxKbaySA37tLD+rjZMjf68gkybHapHNAFR0VOWFe/fb3cmM9RXS7g== From: =?utf-8?q?Th=C3=A9o_Lebrun?= Date: Fri, 03 May 2024 16:20:49 +0200 Subject: [PATCH v2 04/11] driver core: platform: Introduce platform_device_add_with_name() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240503-mbly-olb-v2-4-95ce5a1e18fe@bootlin.com> References: <20240503-mbly-olb-v2-0-95ce5a1e18fe@bootlin.com> In-Reply-To: <20240503-mbly-olb-v2-0-95ce5a1e18fe@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Michael Turquette , Stephen Boyd , Philipp Zabel , Linus Walleij , Greg Kroah-Hartman , "Rafael J. Wysocki" , Lee Jones , Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org, Vladimir Kondratiev , Gregory CLEMENT , Thomas Petazzoni , Tawfik Bayouk , =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: b4 0.13.0 X-GND-Sasl: theo.lebrun@bootlin.com Public function platform_device_add() does three things: - Name device using pdev->name and pdev->id; - Insert resources into resource tree; - device_add(). This implies device name must be based upon pdev->name. Add platform_device_add_with_name() to allow caller to pick device name. pdev->name cannot be picked freely: it might be used to match platform driver id_table or name. This applies to MFD cells for example. In header file, avoid breakage by aliasing platform_device_add(pdev) to platform_device_add_with_name(pdev, NULL). Signed-off-by: Théo Lebrun --- drivers/base/platform.c | 17 +++++++++++------ include/linux/platform_device.h | 12 +++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 10c577963418..dce282cb2e50 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -648,13 +648,15 @@ int platform_device_add_data(struct platform_device *pdev, const void *data, EXPORT_SYMBOL_GPL(platform_device_add_data); /** - * platform_device_add - add a platform device to device hierarchy + * platform_device_add_with_name - add a platform device to device hierarchy * @pdev: platform device we're adding + * @devname: optional device name to assign, fallback to platform device name * * This is part 2 of platform_device_register(), though may be called * separately _iff_ pdev was allocated by platform_device_alloc(). */ -int platform_device_add(struct platform_device *pdev) +int platform_device_add_with_name(struct platform_device *pdev, + const char *devname) { struct device *dev = &pdev->dev; u32 i; @@ -665,12 +667,15 @@ int platform_device_add(struct platform_device *pdev) dev->bus = &platform_bus_type; + if (!devname) + devname = pdev->name; + switch (pdev->id) { default: - dev_set_name(dev, "%s.%d", pdev->name, pdev->id); + dev_set_name(dev, "%s.%d", devname, pdev->id); break; case PLATFORM_DEVID_NONE: - dev_set_name(dev, "%s", pdev->name); + dev_set_name(dev, "%s", devname); break; case PLATFORM_DEVID_AUTO: /* @@ -683,7 +688,7 @@ int platform_device_add(struct platform_device *pdev) return ret; pdev->id = ret; pdev->id_auto = true; - dev_set_name(dev, "%s.%d.auto", pdev->name, pdev->id); + dev_set_name(dev, "%s.%d.auto", devname, pdev->id); break; } @@ -733,7 +738,7 @@ int platform_device_add(struct platform_device *pdev) return ret; } -EXPORT_SYMBOL_GPL(platform_device_add); +EXPORT_SYMBOL_GPL(platform_device_add_with_name); /** * platform_device_del - remove a platform-level device diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 7a41c72c1959..bc1463c83f69 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -229,10 +229,20 @@ extern int platform_device_add_resources(struct platform_device *pdev, unsigned int num); extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size); -extern int platform_device_add(struct platform_device *pdev); +extern int platform_device_add_with_name(struct platform_device *pdev, + const char *devname); extern void platform_device_del(struct platform_device *pdev); extern void platform_device_put(struct platform_device *pdev); +/** + * platform_device_add - add a platform device to device hierarchy + * @pdev: platform device we're adding + */ +static inline int platform_device_add(struct platform_device *pdev) +{ + return platform_device_add_with_name(pdev, NULL); +} + struct platform_driver { int (*probe)(struct platform_device *); -- 2.45.0