Skip to content

Commit ccc9ef4

Browse files
RD Babieravijay-suman
authored andcommitted
usb: typec: altmodes/displayport: create sysfs nodes as driver's default device attribute group
commit 165376f 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]> (cherry picked from commit 9794ffd9d0c39ee070fbd733f862bbe89b28ba33) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent af785e4 commit ccc9ef4

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
@@ -521,22 +521,26 @@ static ssize_t pin_assignment_show(struct device *dev,
521521
}
522522
static DEVICE_ATTR_RW(pin_assignment);
523523

524-
static struct attribute *dp_altmode_attrs[] = {
524+
static struct attribute *displayport_attrs[] = {
525525
&dev_attr_configuration.attr,
526526
&dev_attr_pin_assignment.attr,
527527
NULL
528528
};
529529

530-
static const struct attribute_group dp_altmode_group = {
530+
static const struct attribute_group displayport_group = {
531531
.name = "displayport",
532-
.attrs = dp_altmode_attrs,
532+
.attrs = displayport_attrs,
533+
};
534+
535+
static const struct attribute_group *displayport_groups[] = {
536+
&displayport_group,
537+
NULL,
533538
};
534539

535540
int dp_altmode_probe(struct typec_altmode *alt)
536541
{
537542
const struct typec_altmode *port = typec_altmode_get_partner(alt);
538543
struct dp_altmode *dp;
539-
int ret;
540544

541545
/* FIXME: Port can only be DFP_U. */
542546

@@ -547,10 +551,6 @@ int dp_altmode_probe(struct typec_altmode *alt)
547551
DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
548552
return -ENODEV;
549553

550-
ret = sysfs_create_group(&alt->dev.kobj, &dp_altmode_group);
551-
if (ret)
552-
return ret;
553-
554554
dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
555555
if (!dp)
556556
return -ENOMEM;
@@ -576,7 +576,6 @@ void dp_altmode_remove(struct typec_altmode *alt)
576576
{
577577
struct dp_altmode *dp = typec_altmode_get_drvdata(alt);
578578

579-
sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group);
580579
cancel_work_sync(&dp->work);
581580
}
582581
EXPORT_SYMBOL_GPL(dp_altmode_remove);
@@ -594,6 +593,7 @@ static struct typec_altmode_driver dp_altmode_driver = {
594593
.driver = {
595594
.name = "typec_displayport",
596595
.owner = THIS_MODULE,
596+
.dev_groups = displayport_groups,
597597
},
598598
};
599599
module_typec_altmode_driver(dp_altmode_driver);

0 commit comments

Comments
 (0)