Skip to content

Commit f1c5dda

Browse files
RD Babieragregkh
authored andcommitted
usb: typec: altmodes/displayport: create sysfs nodes as driver's default device attribute group
commit 165376f6b23e9a779850e750fb2eb06622e5a531 upstream. The DisplayPort driver's sysfs nodes may be present to the userspace before typec_altmode_set_drvdata() completes in dp_altmode_probe. This means that a sysfs read can trigger a NULL pointer error by deferencing dp->hpd in hpd_show or dp->lock in pin_assignment_show, as dev_get_drvdata() returns NULL in those cases. Remove manual sysfs node creation in favor of adding attribute group as default for devices bound to the driver. The ATTRIBUTE_GROUPS() macro is not used here otherwise the path to the sysfs nodes is no longer compliant with the ABI. Fixes: 0e3bb7d ("usb: typec: Add driver for DisplayPort alternate mode") Cc: [email protected] Signed-off-by: RD Babiera <[email protected]> Link: https://lore.kernel.org/r/[email protected] [Minor conflict resolved due to code context change.] Signed-off-by: Jianqi Ren <[email protected]> Signed-off-by: He Zhe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f32451c commit f1c5dda

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/usb/typec/altmodes/displayport.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,23 +543,27 @@ static ssize_t pin_assignment_show(struct device *dev,
543543
}
544544
static DEVICE_ATTR_RW(pin_assignment);
545545

546-
static struct attribute *dp_altmode_attrs[] = {
546+
static struct attribute *displayport_attrs[] = {
547547
&dev_attr_configuration.attr,
548548
&dev_attr_pin_assignment.attr,
549549
NULL
550550
};
551551

552-
static const struct attribute_group dp_altmode_group = {
552+
static const struct attribute_group displayport_group = {
553553
.name = "displayport",
554-
.attrs = dp_altmode_attrs,
554+
.attrs = displayport_attrs,
555+
};
556+
557+
static const struct attribute_group *displayport_groups[] = {
558+
&displayport_group,
559+
NULL,
555560
};
556561

557562
int dp_altmode_probe(struct typec_altmode *alt)
558563
{
559564
const struct typec_altmode *port = typec_altmode_get_partner(alt);
560565
struct fwnode_handle *fwnode;
561566
struct dp_altmode *dp;
562-
int ret;
563567

564568
/* FIXME: Port can only be DFP_U. */
565569

@@ -570,10 +574,6 @@ int dp_altmode_probe(struct typec_altmode *alt)
570574
DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
571575
return -ENODEV;
572576

573-
ret = sysfs_create_group(&alt->dev.kobj, &dp_altmode_group);
574-
if (ret)
575-
return ret;
576-
577577
dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
578578
if (!dp)
579579
return -ENOMEM;
@@ -604,7 +604,6 @@ void dp_altmode_remove(struct typec_altmode *alt)
604604
{
605605
struct dp_altmode *dp = typec_altmode_get_drvdata(alt);
606606

607-
sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group);
608607
cancel_work_sync(&dp->work);
609608

610609
if (dp->connector_fwnode) {
@@ -629,6 +628,7 @@ static struct typec_altmode_driver dp_altmode_driver = {
629628
.driver = {
630629
.name = "typec_displayport",
631630
.owner = THIS_MODULE,
631+
.dev_groups = displayport_groups,
632632
},
633633
};
634634
module_typec_altmode_driver(dp_altmode_driver);

0 commit comments

Comments
 (0)