staging: greybus: light: fix a couple double frees
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 29 Aug 2019 12:28:39 +0000 (15:28 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Jan 2020 13:51:08 +0000 (14:51 +0100)
commit8e456b4b1a3b91aa5cd59813a0bdc99f41de5f00
tree50f86f310a87c6f3c64e9e762ad9d8dd4e06b06a
parentb686bc28e5747072766cc6c489a3c2f7a0c1581f
staging: greybus: light: fix a couple double frees

[ Upstream commit 329101244f214952606359d254ae883b7109e1a5 ]

The problem is in gb_lights_request_handler().  If we get a request to
change the config then we release the light with gb_lights_light_release()
and re-allocated it.  However, if the allocation fails part way through
then we call gb_lights_light_release() again.  This can lead to a couple
different double frees where we haven't cleared out the original values:

gb_lights_light_v4l2_unregister(light);
...
kfree(light->channels);
kfree(light->name);

I also made a small change to how we set "light->channels_count = 0;".
The original code handled this part fine and did not cause a use after
free but it was sort of complicated to read.

Fixes: 2870b52bae4c ("greybus: lights: add lights implementation")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Link: https://lore.kernel.org/r/20190829122839.GA20116@mwanda
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/staging/greybus/light.c