linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Cc: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: typec: Check error number after calling ida_simple_get
Date: Tue, 11 Jan 2022 09:39:13 +0100	[thread overview]
Message-ID: <Yd1CMdAzIXaT/QBB@kroah.com> (raw)
In-Reply-To: <20220111071751.590487-1-jiasheng@iscas.ac.cn>

On Tue, Jan 11, 2022 at 03:17:51PM +0800, Jiasheng Jiang wrote:
> If allocation fails, the ida_simple_get() will return error number.

How can allocation fail?  Have you been able to trigger this?

> So altmode_id_get() may return error number.
> And then id will be used in altmode_id_remove, causing the BUG_ON().
> Or it will be assigned to alt->id.
> Therefore, it should be better to check it and return error if fails,
> like the ida_simple_get() in typec_register_port().
> 
> Fixes: 8a37d87d72f0 ("usb: typec: Bus type for alternate modes")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/usb/typec/class.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index aeef453aa658..67b3670ede99 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -516,6 +516,9 @@ typec_register_altmode(struct device *parent,
>  	struct altmode *alt;
>  	int ret;
>  
> +	if (id < 0)
> +		return ERR_PTR(id);
> +
>  	alt = kzalloc(sizeof(*alt), GFP_KERNEL);
>  	if (!alt) {
>  		altmode_id_remove(parent, id);
> -- 
> 2.25.1
> 

How did you test that this change will work properly?

As I have said before, I'm not going to take changes from you unless you
can prove they have been tested, due to all of the previous problems in
your submitted patches.

greg k-h

      reply	other threads:[~2022-01-11  8:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11  7:17 [PATCH] usb: typec: Check error number after calling ida_simple_get Jiasheng Jiang
2022-01-11  8:39 ` Greg KH [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=Yd1CMdAzIXaT/QBB@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=heikki.krogerus@linux.intel.com \
    --cc=jiasheng@iscas.ac.cn \
    --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;
as well as URLs for NNTP newsgroup(s).