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 [Minor conflict resolved due to code context change.]
26 Signed-off-by: Jianqi Ren <jianqi.ren.cn@windriver.com>
27 Signed-off-by: He Zhe <zhe.he@windriver.com>
28 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 drivers/usb/typec/altmodes/displayport.c | 18 +++++++++---------
31 1 file changed, 9 insertions(+), 9 deletions(-)
33 --- a/drivers/usb/typec/altmodes/displayport.c
34 +++ b/drivers/usb/typec/altmodes/displayport.c
35 @@ -527,15 +527,20 @@ static ssize_t pin_assignment_show(struc
37 static DEVICE_ATTR_RW(pin_assignment);
39 -static struct attribute *dp_altmode_attrs[] = {
40 +static struct attribute *displayport_attrs[] = {
41 &dev_attr_configuration.attr,
42 &dev_attr_pin_assignment.attr,
46 -static const struct attribute_group dp_altmode_group = {
47 +static const struct attribute_group displayport_group = {
48 .name = "displayport",
49 - .attrs = dp_altmode_attrs,
50 + .attrs = displayport_attrs,
53 +static const struct attribute_group *displayport_groups[] = {
58 int dp_altmode_probe(struct typec_altmode *alt)
59 @@ -543,7 +548,6 @@ int dp_altmode_probe(struct typec_altmod
60 const struct typec_altmode *port = typec_altmode_get_partner(alt);
61 struct fwnode_handle *fwnode;
62 struct dp_altmode *dp;
65 /* FIXME: Port can only be DFP_U. */
67 @@ -554,10 +558,6 @@ int dp_altmode_probe(struct typec_altmod
68 DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
71 - ret = sysfs_create_group(&alt->dev.kobj, &dp_altmode_group);
75 dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
78 @@ -588,7 +588,6 @@ void dp_altmode_remove(struct typec_altm
80 struct dp_altmode *dp = typec_altmode_get_drvdata(alt);
82 - sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group);
83 cancel_work_sync(&dp->work);
85 if (dp->connector_fwnode) {
86 @@ -613,6 +612,7 @@ static struct typec_altmode_driver dp_al
88 .name = "typec_displayport",
90 + .dev_groups = displayport_groups,
93 module_typec_altmode_driver(dp_altmode_driver);