]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
99f846cacdb2605cc4e90a7c7996766396cb1c86
[thirdparty/kernel/stable-queue.git] /
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
5
6 From: RD Babiera <rdbabiera@google.com>
7
8 commit 165376f6b23e9a779850e750fb2eb06622e5a531 upstream.
9
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
14 NULL in those cases.
15
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
19 with the ABI.
20
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>
26 ---
27 drivers/usb/typec/altmodes/displayport.c | 18 +++++++++---------
28 1 file changed, 9 insertions(+), 9 deletions(-)
29
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
33 }
34 static DEVICE_ATTR_RO(hpd);
35
36 -static struct attribute *dp_altmode_attrs[] = {
37 +static struct attribute *displayport_attrs[] = {
38 &dev_attr_configuration.attr,
39 &dev_attr_pin_assignment.attr,
40 &dev_attr_hpd.attr,
41 NULL
42 };
43
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,
49 +};
50 +
51 +static const struct attribute_group *displayport_groups[] = {
52 + &displayport_group,
53 + NULL,
54 };
55
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;
61 - int ret;
62
63 /* FIXME: Port can only be DFP_U. */
64
65 @@ -587,10 +591,6 @@ int dp_altmode_probe(struct typec_altmod
66 DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
67 return -ENODEV;
68
69 - ret = sysfs_create_group(&alt->dev.kobj, &dp_altmode_group);
70 - if (ret)
71 - return ret;
72 -
73 dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
74 if (!dp)
75 return -ENOMEM;
76 @@ -624,7 +624,6 @@ void dp_altmode_remove(struct typec_altm
77 {
78 struct dp_altmode *dp = typec_altmode_get_drvdata(alt);
79
80 - sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group);
81 cancel_work_sync(&dp->work);
82
83 if (dp->connector_fwnode) {
84 @@ -649,6 +648,7 @@ static struct typec_altmode_driver dp_al
85 .driver = {
86 .name = "typec_displayport",
87 .owner = THIS_MODULE,
88 + .dev_groups = displayport_groups,
89 },
90 };
91 module_typec_altmode_driver(dp_altmode_driver);