Message ID | 20201116121710.1546690-2-zhangqilong3@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | usb: gadget: Fix two memleaks in error handling | expand |
On 20-11-16 20:17:09, Zhang Qilong wrote: > In the error path, if midi is not null, we should to > free the midi->id if necessary to prevent memleak. > > Fixes: b85e9de9e818d ("usb: gadget: f_midi: convert to new function interface with backward compatibility") > Reported-by: Hulk Robot <hulkci@huawei.com> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> > --- > drivers/usb/gadget/function/f_midi.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c > index 85cb15734aa8..596fd7ce56fb 100644 > --- a/drivers/usb/gadget/function/f_midi.c > +++ b/drivers/usb/gadget/function/f_midi.c > @@ -1345,7 +1345,10 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi) > > setup_fail: > mutex_unlock(&opts->lock); > + if (midi) > + kfree(midi->id); > kfree(midi); > + > return ERR_PTR(status); > } > It is better to add another goto label for this memory free.
On 11/16/20 3:17 PM, Zhang Qilong wrote: > In the error path, if midi is not null, we should to That "to" not needed here. > free the midi->id if necessary to prevent memleak. > > Fixes: b85e9de9e818d ("usb: gadget: f_midi: convert to new function interface with backward compatibility") > Reported-by: Hulk Robot <hulkci@huawei.com> > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> [...] MBR, Sergei
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c index 85cb15734aa8..596fd7ce56fb 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -1345,7 +1345,10 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi) setup_fail: mutex_unlock(&opts->lock); + if (midi) + kfree(midi->id); kfree(midi); + return ERR_PTR(status); }
In the error path, if midi is not null, we should to free the midi->id if necessary to prevent memleak. Fixes: b85e9de9e818d ("usb: gadget: f_midi: convert to new function interface with backward compatibility") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> --- drivers/usb/gadget/function/f_midi.c | 3 +++ 1 file changed, 3 insertions(+)