usb: typec: tcpm: fix create duplicate source-capabilities file
authorXu Yang <xu.yang_2@nxp.com>
Wed, 15 Feb 2023 05:49:51 +0000 (13:49 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Mar 2023 14:15:05 +0000 (15:15 +0100)
commita826492fc9dfe32afd70fff93955ae8174bbf14b
tree2cb71b1b048c4abcc80a4093b7bdfaf157c15086
parent6c67ed9ad9b83e453e808f9b31a931a20a25629b
usb: typec: tcpm: fix create duplicate source-capabilities file

The kernel will dump in the below cases:
sysfs: cannot create duplicate filename
'/devices/virtual/usb_power_delivery/pd1/source-capabilities'

1. After soft reset has completed, an Explicit Contract negotiation occurs.
The sink device will receive source capabilitys again. This will cause
a duplicate source-capabilities file be created.
2. Power swap twice on a device that is initailly sink role.

This will unregister existing capabilities when above cases occurs.

Fixes: 8203d26905ee ("usb: typec: tcpm: Register USB Power Delivery Capabilities")
cc: <stable@vger.kernel.org>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Link: https://lore.kernel.org/r/20230215054951.238394-1-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/tcpm.c