mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Colin King <colin.king@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] usb: typec: unlock dp->lock on error exit path, and also zero ret if successful
Date: Thu, 5 Jul 2018 16:18:01 +0300	[thread overview]
Message-ID: <20180705131801.GD15989@kuha.fi.intel.com> (raw)
In-Reply-To: <20180704124611.9852-1-colin.king@canonical.com>

On Wed, Jul 04, 2018 at 01:46:11PM +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>
> ---
>  drivers/usb/typec/altmodes/displayport.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index ef12b15bd484..9a637c2b4460 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -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;
> @@ -362,6 +364,7 @@ configuration_store(struct device *dev, struct device_attribute *attr,
>  	}
>  
>  	dp->data.conf = conf;
> +	ret = 0;

Could you set the value when the variable is introduced:

        int ret = 0;


Thank you,

-- 
heikki

      reply	other threads:[~2018-07-05 13:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04 12:46 Colin King
2018-07-05 13:18 ` Heikki Krogerus [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180705131801.GD15989@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=colin.king@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome