w1_therm: Free the correct variable
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 20 May 2020 12:00:19 +0000 (15:00 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 21 May 2020 08:58:46 +0000 (10:58 +0200)
The problem is that we change "p_args" to point to the middle of the
string so when we free it at the end of the function it's not freeing
the same pointer that we originally allocated.

Fixes: e2c94d6f5720 ("w1_therm: adding alarm sysfs entry")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/20200520120019.GA172354@mwanda
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/w1/slaves/w1_therm.c

index cc4b88056b3384ee2a2883ea534a60ea78635d2e..a6c85e486671978d2d7aeb3081460ab9daa5ffd7 100644 (file)
@@ -1526,8 +1526,9 @@ static ssize_t alarms_store(struct device *device,
        int temp, ret = -EINVAL;
        char *token = NULL;
        s8 tl, th, tt;  /* 1 byte per value + temp ring order */
-       char *p_args = kmalloc(size, GFP_KERNEL);
+       char *p_args, *orig;
 
+       p_args = orig = kmalloc(size, GFP_KERNEL);
        /* Safe string copys as buf is const */
        if (!p_args) {
                dev_warn(device,
@@ -1611,7 +1612,7 @@ static ssize_t alarms_store(struct device *device,
 
 free_m:
        /* free allocated memory */
-       kfree(p_args);
+       kfree(orig);
 
        return size;
 }