public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Philippe De Swert <philippe.deswert@jollamobile.com>
To: balbi@ti.com
Cc: linux-usb@vger.kernel.org, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: gadget/composite : Avoid crash with bad gadget drivers
Date: Thu, 15 Aug 2013 01:40:01 +0300	[thread overview]
Message-ID: <520C0741.3010905@jollamobile.com> (raw)
In-Reply-To: <20130812180804.GE27954@radagast>

Hi,

On 12/08/13 21:08, Felipe Balbi wrote:
> On Fri, Aug 09, 2013 at 09:23:08PM +0300, Philippe De Swert wrote:
>> Some bad gadget drivers do not check the return status of usb_add_config.
>
> fix the gadget driver

As stated in my comment (see below) that is indeed what should happen. 
But we cannot fix it in future new gadget drivers, is it thus not better
to avoid a crash? The gadget driver will not work as expected anyway 
when this occurs and the print will at least give an indication why.

>> Thus they get a not correctly initialized config and when this gadget gets
>> deactivated the whole kernel crashes. Since on initialization failure cdev
>> is set to NULL it can be used to detect this problem situation. It can be
>> argued that the faulty gadget driver should be fixed, but imho it is better
>> to avoid crashing the kernel and letting the gadget developer know he/she
>> is making a mistake. And have the developer of said gadget driver then fix
>> the problem of course.
>>
>> Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
>> ---
>>   drivers/usb/gadget/composite.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
>> index 55f4df6..e019bb5 100644
>> --- a/drivers/usb/gadget/composite.c
>> +++ b/drivers/usb/gadget/composite.c
>> @@ -848,12 +848,18 @@ void usb_remove_config(struct usb_composite_dev *cdev,
>>   {
>>   	unsigned long flags;
>>
>> +	if (config->cdev == NULL) {
>> +		pr_warn("Calling usb_remove_config without a matching usb_add_config!\n");
>> +		goto end;
>> +	}
>
> I would take a WARN() only, but let the crash happen and fix the gadget
> driver.
>

Since the kernel will crash with a NULL dereference anyway is BUG_ON not 
a better approach then?

Regards,

Philippe

  reply	other threads:[~2013-08-14 22:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09 18:23 [PATCH] usb: gadget/composite : Avoid crash with bad gadget drivers Philippe De Swert
2013-08-12 18:08 ` Felipe Balbi
2013-08-14 22:40   ` Philippe De Swert [this message]
2013-08-27 18:55     ` Felipe Balbi

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=520C0741.3010905@jollamobile.com \
    --to=philippe.deswert@jollamobile.com \
    --cc=balbi@ti.com \
    --cc=gregkh@linuxfoundation.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