* [PATCH][V2] usb: typec: unlock dp->lock on error exit path, and also zero ret if successful
@ 2018-07-05 13:36 Colin King
2018-07-06 7:10 ` Heikki Krogerus
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2018-07-05 13:36 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman, linux-usb
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
One of the error handling paths forgets to unlock dp->lock on the error
exit path leading to a potential lock-up. Also the return path for a
successful call to the function configuration_store can return an
uninitialized error return code if dp->alt->active is false, so ensure
ret is zeroed on the successful exit path to avoid garbage being returned.
Detected by CoverityScan, CID#1471597 ("Unitialized scalar variable")
Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
V2: move the ret = 0 assignment to the declaration
---
drivers/usb/typec/altmodes/displayport.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index ef12b15bd484..3f06e94771a7 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -333,7 +333,7 @@ configuration_store(struct device *dev, struct device_attribute *attr,
u32 conf;
u32 cap;
int con;
- int ret;
+ int ret = 0;
con = sysfs_match_string(configurations, buf);
if (con < 0)
@@ -349,8 +349,10 @@ configuration_store(struct device *dev, struct device_attribute *attr,
cap = DP_CAP_CAPABILITY(dp->alt->vdo);
if ((con == DP_CONF_DFP_D && !(cap & DP_CAP_DFP_D)) ||
- (con == DP_CONF_UFP_D && !(cap & DP_CAP_UFP_D)))
- return -EINVAL;
+ (con == DP_CONF_UFP_D && !(cap & DP_CAP_UFP_D))) {
+ ret = -EINVAL;
+ goto err_unlock;
+ }
conf = dp->data.conf & ~DP_CONF_DUAL_D;
conf |= con;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][V2] usb: typec: unlock dp->lock on error exit path, and also zero ret if successful
2018-07-05 13:36 [PATCH][V2] usb: typec: unlock dp->lock on error exit path, and also zero ret if successful Colin King
@ 2018-07-06 7:10 ` Heikki Krogerus
0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2018-07-06 7:10 UTC (permalink / raw)
To: Colin King; +Cc: Greg Kroah-Hartman, linux-usb, kernel-janitors, linux-kernel
On Thu, Jul 05, 2018 at 02:36:47PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> One of the error handling paths forgets to unlock dp->lock on the error
> exit path leading to a potential lock-up. Also the return path for a
> successful call to the function configuration_store can return an
> uninitialized error return code if dp->alt->active is false, so ensure
> ret is zeroed on the successful exit path to avoid garbage being returned.
>
> Detected by CoverityScan, CID#1471597 ("Unitialized scalar variable")
>
> Fixes: 0e3bb7d6894d ("usb: typec: Add driver for DisplayPort alternate mode")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>
> V2: move the ret = 0 assignment to the declaration
>
> ---
> drivers/usb/typec/altmodes/displayport.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index ef12b15bd484..3f06e94771a7 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -333,7 +333,7 @@ configuration_store(struct device *dev, struct device_attribute *attr,
> u32 conf;
> u32 cap;
> int con;
> - int ret;
> + int ret = 0;
>
> con = sysfs_match_string(configurations, buf);
> if (con < 0)
> @@ -349,8 +349,10 @@ configuration_store(struct device *dev, struct device_attribute *attr,
> cap = DP_CAP_CAPABILITY(dp->alt->vdo);
>
> if ((con == DP_CONF_DFP_D && !(cap & DP_CAP_DFP_D)) ||
> - (con == DP_CONF_UFP_D && !(cap & DP_CAP_UFP_D)))
> - return -EINVAL;
> + (con == DP_CONF_UFP_D && !(cap & DP_CAP_UFP_D))) {
> + ret = -EINVAL;
> + goto err_unlock;
> + }
>
> conf = dp->data.conf & ~DP_CONF_DUAL_D;
> conf |= con;
Thanks,
--
heikki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-06 7:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-05 13:36 [PATCH][V2] usb: typec: unlock dp->lock on error exit path, and also zero ret if successful Colin King
2018-07-06 7:10 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).