lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221121062106.2569297-1-pmalani@chromium.org>
Date:   Mon, 21 Nov 2022 06:20:39 +0000
From:   Prashant Malani <pmalani@...omium.org>
To:     linux-kernel@...r.kernel.org, linux-usb@...r.kernel.org
Cc:     Prashant Malani <pmalani@...omium.org>,
        Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
        Benson Leung <bleung@...omium.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: [PATCH] usb: typec: pd: Add symlink to linked device

There exists a symlink from a device to its USB Power Delivery object,
but not the other way around. Add a symlink from the USB PD object to
the device which it's associated with, and call it "device".

This is helpful to identify said device (a Type-C peripheral for
example) during uevents, since during USB PD object
creation/destruction, a uevent is generated for the PD object,
but not the device linked to it.

Cc: Heikki Krogerus <heikki.krogerus@...ux.intel.com>
Cc: Benson Leung <bleung@...omium.org>
Signed-off-by: Prashant Malani <pmalani@...omium.org>
---
 .../ABI/testing/sysfs-class-usb_power_delivery       |  6 ++++++
 drivers/usb/typec/pd.c                               | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-class-usb_power_delivery b/Documentation/ABI/testing/sysfs-class-usb_power_delivery
index ce2b1b563cb3..e7d19193875f 100644
--- a/Documentation/ABI/testing/sysfs-class-usb_power_delivery
+++ b/Documentation/ABI/testing/sysfs-class-usb_power_delivery
@@ -4,6 +4,12 @@ Contact:	Heikki Krogerus <heikki.krogerus@...ux.intel.com>
 Description:
 		Directory for USB Power Delivery devices.
 
+What:		/sys/class/usb_power_delivery/.../device
+Date:		November 2022
+Contact:	Prashant Malani <pmalani@...omium.org>
+Description:
+		Symbolic link to the directory of the device to which the USB PD object is linked.
+
 What:		/sys/class/usb_power_delivery/.../revision
 Date:		May 2022
 Contact:	Heikki Krogerus <heikki.krogerus@...ux.intel.com>
diff --git a/drivers/usb/typec/pd.c b/drivers/usb/typec/pd.c
index dc72005d68db..ed073d922655 100644
--- a/drivers/usb/typec/pd.c
+++ b/drivers/usb/typec/pd.c
@@ -656,7 +656,8 @@ EXPORT_SYMBOL_GPL(usb_power_delivery_unregister);
  * @dev: The device.
  *
  * This function can be used to create a symlink named "usb_power_delivery" for
- * @dev that points to @pd.
+ * @dev that points to @pd. It also creates another symlink named "device" which
+ * points from @pd to @dev.
  */
 int usb_power_delivery_link_device(struct usb_power_delivery *pd, struct device *dev)
 {
@@ -669,6 +670,12 @@ int usb_power_delivery_link_device(struct usb_power_delivery *pd, struct device
 	if (ret)
 		return ret;
 
+	ret = sysfs_create_link(&pd->dev.kobj, &dev->kobj, "device");
+	if (ret) {
+		sysfs_remove_link(&dev->kobj, "usb_power_delivery");
+		return ret;
+	}
+
 	get_device(&pd->dev);
 	get_device(dev);
 
@@ -681,13 +688,14 @@ EXPORT_SYMBOL_GPL(usb_power_delivery_link_device);
  * @pd: The USB PD instance.
  * @dev: The device.
  *
- * Remove the symlink that was previously created with pd_link_device().
+ * Remove the symlinks that were previously created with pd_link_device().
  */
 void usb_power_delivery_unlink_device(struct usb_power_delivery *pd, struct device *dev)
 {
 	if (IS_ERR_OR_NULL(pd) || !dev)
 		return;
 
+	sysfs_remove_link(&pd->dev.kobj, "device");
 	sysfs_remove_link(&dev->kobj, "usb_power_delivery");
 	put_device(&pd->dev);
 	put_device(dev);
-- 
2.38.1.584.g0f3c55d4c2-goog

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ