1 From 165376f6b23e9a779850e750fb2eb06622e5a531 Mon Sep 17 00:00:00 2001
2 From: RD Babiera <rdbabiera@google.com>
3 Date: Thu, 29 Feb 2024 00:11:02 +0000
4 Subject: usb: typec: altmodes/displayport: create sysfs nodes as driver's default device attribute group
6 From: RD Babiera <rdbabiera@google.com>
8 commit 165376f6b23e9a779850e750fb2eb06622e5a531 upstream.
10 The DisplayPort driver's sysfs nodes may be present to the userspace before
11 typec_altmode_set_drvdata() completes in dp_altmode_probe. This means that
12 a sysfs read can trigger a NULL pointer error by deferencing dp->hpd in
13 hpd_show or dp->lock in pin_assignment_show, as dev_get_drvdata() returns
16 Remove manual sysfs node creation in favor of adding attribute group as
17 default for devices bound to the driver. The ATTRIBUTE_GROUPS() macro is
18 not used here otherwise the path to the sysfs nodes is no longer compliant
21 Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
22 Cc: stable@vger.kernel.org
23 Signed-off-by: RD Babiera <rdbabiera@google.com>
24 Link: https://lore.kernel.org/r/20240229001101.3889432-2-rdbabiera@google.com
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
27 drivers/usb/typec/altmodes/displayport.c | 18 +++++++++---------
28 1 file changed, 9 insertions(+), 9 deletions(-)
30 --- a/drivers/usb/typec/altmodes/displayport.c
31 +++ b/drivers/usb/typec/altmodes/displayport.c
32 @@ -559,16 +559,21 @@ static ssize_t hpd_show(struct device *d
34 static DEVICE_ATTR_RO(hpd);
36 -static struct attribute *dp_altmode_attrs[] = {
37 +static struct attribute *displayport_attrs[] = {
38 &dev_attr_configuration.attr,
39 &dev_attr_pin_assignment.attr,
44 -static const struct attribute_group dp_altmode_group = {
45 +static const struct attribute_group displayport_group = {
46 .name = "displayport",
47 - .attrs = dp_altmode_attrs,
48 + .attrs = displayport_attrs,
51 +static const struct attribute_group *displayport_groups[] = {
56 int dp_altmode_probe(struct typec_altmode *alt)
57 @@ -576,7 +581,6 @@ int dp_altmode_probe(struct typec_altmod
58 const struct typec_altmode *port = typec_altmode_get_partner(alt);
59 struct fwnode_handle *fwnode;
60 struct dp_altmode *dp;
63 /* FIXME: Port can only be DFP_U. */
65 @@ -587,10 +591,6 @@ int dp_altmode_probe(struct typec_altmod
66 DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
69 - ret = sysfs_create_group(&alt->dev.kobj, &dp_altmode_group);
73 dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
76 @@ -624,7 +624,6 @@ void dp_altmode_remove(struct typec_altm
78 struct dp_altmode *dp = typec_altmode_get_drvdata(alt);
80 - sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group);
81 cancel_work_sync(&dp->work);
83 if (dp->connector_fwnode) {
84 @@ -649,6 +648,7 @@ static struct typec_altmode_driver dp_al
86 .name = "typec_displayport",
88 + .dev_groups = displayport_groups,
91 module_typec_altmode_driver(dp_altmode_driver);