Re: [PATCH v3 2/2] kunit: avoid memory leak on device register error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> If the device register fails, free the allocated memory before
> returning.

Can a description variant (like the following) be more appropriate?

   Free the allocated memory (after a device registration failure)
   before returning.
   Thus add a jump target so that a bit of exception handling can be better
   reused at the end of this function implementation.


Would you like to replace the word “register” by “registration” also
in the summary phrase?


…
> +++ b/lib/kunit/device.c
…
> @@ -140,6 +138,9 @@ static struct kunit_device *kunit_device_register_internal(struct kunit *test,
>  	kunit_add_action(test, device_unregister_wrapper, &kunit_dev->dev);
>
>  	return kunit_dev;
> +error:
> +	kfree(kunit_dev);
> +	return ERR_PTR(err);
>  }
…

I find it nicer to use a label like free_device.

Regards,
Markus





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux