Re: [PATCH 1/1] usb: gadget: add raw-gadget interface
From: Greg Kroah-Hartman
Date: Thu Nov 14 2019 - 22:20:04 EST
On Thu, Nov 14, 2019 at 04:08:29PM +0100, Andrey Konovalov wrote:
> On Fri, Nov 8, 2019 at 10:17 PM Greg Kroah-Hartman
> > > +static void gadget_unbind(struct usb_gadget *gadget)
> > > +{
> > > + struct raw_dev *dev = get_gadget_data(gadget);
> > > + unsigned long flags;
> > > +
> > > + if (WARN_ON(!dev))
> > > + return;
> >
> > Why warn? How can this happen?
>
> This shouldn't happen and I initially had BUG_ON there, but checkpatch
> complained. I can use BUG_ON of leave it as WARN_ON, which would you
> prefer?
If it should never happen, then why test it?
If it can happen, then just test and print an error, why panic the
machine if panic-on-warn is enabled for something that we can test and
recover from?
And no, never add BUG_ON please.
> > > +static int raw_open(struct inode *inode, struct file *fd)
> > > +{
> > > + struct raw_dev *dev;
> > > +
> > > + dev = dev_new();
> > > + if (!dev) {
> > > + pr_err("failed to created device");
> >
> > So many error messages printed on failures, you only needed the original
> > one if memory was gone that the core sent out.
>
> What do you mean by the original one? I see only one error printed in
> case dev_new() fails. However I'm not sure if there's much value in
> printing an error in case the kernel ran out of memory, as it doesn't
> handle this very well anyway AFAIK. Should I remove this pr_err?
Yes, please do.
thanks,
greg k-h