On Mon, Nov 25, 2019 at 11:54:09PM +0800, Wen Yang wrote:
If device_register() fails, both put_device() and kfree()
are called, ending with a double free of the scmi_dev.
Correct.
Calling kfree() is needed only when a failure happens between the
allocation of the scmi_dev and its registration, so move it to
there and remove it from the error flow.
kstrdup_const can fail and in that case device is not yet registered,
so we need to free. Since device_register() calls put_device() on failure
too, I would just drop it as it's unnecessary, not sure why I have added
it in the first place. Can you re-spin the patch dropping put_device
and renaming put_dev label to something like free_const.
--
Regards,
Sudeep