hwmon: (acpi_power_meter) clean up freeing code
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 7 Oct 2020 07:51:48 +0000 (10:51 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 3 Dec 2020 01:42:22 +0000 (17:42 -0800)
commit96eca8c97fccd3c02f61a87b0341a079b4096730
treec4138ffcfa285661924f9613b3ea81c51ec5cc06
parentbce776f10069c806290eaac712ba73432ae8ecd7
hwmon: (acpi_power_meter) clean up freeing code

This code works okay but Smatch flagged it as a double free.  I've
changed three things to make it more clear.  1)  Remove the call to
free_capabilities() in acpi_power_meter_add().  This call is a no-op
because the capabilities have not been allocated yet.  2)  Set "*str" to
NULL in free_capabilities() so that way the function can be called twice
in a row without leading to a double free.  3)  Call free_capabilities()
in read_capabilities() instead of open coding the free.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20201007075148.GB2529578@mwanda
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/acpi_power_meter.c