Re: [PATCH 2/3] staging: android: ion: Add ion driver for Hi6220 SoC platform

From: Dan Carpenter
Date: Fri Oct 09 2015 - 04:59:31 EST


On Fri, Oct 09, 2015 at 11:53:32AM +0300, Dan Carpenter wrote:
> > +out:
>
> Labels named "out" are bug prone because handling everything is harder
> than using named labels and unwinding one step at a time. The bug here
> is that we don't call ion_device_destroy().
>
> > + for (i = 0; i < num_heaps; ++i)
> > + ion_heap_destroy(heaps[i]);
> > + return err;
>
> Write it like this:
>
> err_free_heaps:
> for (i = 0; i < num_heaps; ++i)
> ion_heap_destroy(heaps[i]);
> err_free_idev:
> ion_device_destroy(idev);
>
> return err;
>
> > +}
> > +
> > +static int hi6220_ion_remove(struct platform_device *pdev)
> > +{
> > + int i;
> > +
> > + ion_device_destroy(idev);
> > + for (i = 0; i < num_heaps; i++) {
> > + if (!heaps[i])
> > + continue;
>
> We don't really need this NULL check and it isn't there in the
> hi6220_ion_probe() unwind code.
>
> > + ion_heap_destroy(heaps[i]);
> > + heaps[i] = NULL;
> > + }
> > +

Really the unwind from probe() and the remove() function should have
similar code. For example, is it important to set heaps[i] to NULL?
If so then we should do it in the probe function as well. If not then
we could leave it out of the remove function.

Also the ion_device_destroy(idev) should be after freeing heaps in the
remove function.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/