Skip to content

Commit 165376f

Browse files
RD Babieragregkh
authored andcommitted
usb: typec: altmodes/displayport: create sysfs nodes as driver's default device attribute group
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] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 197331b commit 165376f

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
@@ -559,24 +559,28 @@ static ssize_t hpd_show(struct device *dev, struct device_attribute *attr, char
559559
}
560560
static DEVICE_ATTR_RO(hpd);
561561

562-
static struct attribute *dp_altmode_attrs[] = {
562+
static struct attribute *displayport_attrs[] = {
563563
&dev_attr_configuration.attr,
564564
&dev_attr_pin_assignment.attr,
565565
&dev_attr_hpd.attr,
566566
NULL
567567
};
568568

569-
static const struct attribute_group dp_altmode_group = {
569+
static const struct attribute_group displayport_group = {
570570
.name = "displayport",
571-
.attrs = dp_altmode_attrs,
571+
.attrs = displayport_attrs,
572+
};
573+
574+
static const struct attribute_group *displayport_groups[] = {
575+
&displayport_group,
576+
NULL,
572577
};
573578

574579
int dp_altmode_probe(struct typec_altmode *alt)
575580
{
576581
const struct typec_altmode *port = typec_altmode_get_partner(alt);
577582
struct fwnode_handle *fwnode;
578583
struct dp_altmode *dp;
579-
int ret;
580584

581585
/* FIXME: Port can only be DFP_U. */
582586

@@ -587,10 +591,6 @@ int dp_altmode_probe(struct typec_altmode *alt)
587591
DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
588592
return -ENODEV;
589593

590-
ret = sysfs_create_group(&alt->dev.kobj, &dp_altmode_group);
591-
if (ret)
592-
return ret;
593-
594594
dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
595595
if (!dp)
596596
return -ENOMEM;
@@ -624,7 +624,6 @@ void dp_altmode_remove(struct typec_altmode *alt)
624624
{
625625
struct dp_altmode *dp = typec_altmode_get_drvdata(alt);
626626

627-
sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group);
628627
cancel_work_sync(&dp->work);
629628

630629
if (dp->connector_fwnode) {
@@ -649,6 +648,7 @@ static struct typec_altmode_driver dp_altmode_driver = {
649648
.driver = {
650649
.name = "typec_displayport",
651650
.owner = THIS_MODULE,
651+
.dev_groups = displayport_groups,
652652
},
653653
};
654654
module_typec_altmode_driver(dp_altmode_driver);

0 commit comments

Comments
 (0)