bcm27xx: import latest patches from the RPi foundation
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0774-w1_therm-Free-the-correct-variable.patch
1 From 039babe99fda6eb04a77ca29cacf98efd1a5f406 Mon Sep 17 00:00:00 2001
2 From: Dan Carpenter <dan.carpenter@oracle.com>
3 Date: Wed, 20 May 2020 15:00:19 +0300
4 Subject: [PATCH] w1_therm: Free the correct variable
5
6 commit e420637b81f78d0fbacf539bdb1b341eba602aea upstream.
7
8 The problem is that we change "p_args" to point to the middle of the
9 string so when we free it at the end of the function it's not freeing
10 the same pointer that we originally allocated.
11
12 Fixes: e2c94d6f5720 ("w1_therm: adding alarm sysfs entry")
13 Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
14 Link: https://lore.kernel.org/r/20200520120019.GA172354@mwanda
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17 drivers/w1/slaves/w1_therm.c | 5 +++--
18 1 file changed, 3 insertions(+), 2 deletions(-)
19
20 --- a/drivers/w1/slaves/w1_therm.c
21 +++ b/drivers/w1/slaves/w1_therm.c
22 @@ -1526,8 +1526,9 @@ static ssize_t alarms_store(struct devic
23 int temp, ret = -EINVAL;
24 char *token = NULL;
25 s8 tl, th, tt; /* 1 byte per value + temp ring order */
26 - char *p_args = kmalloc(size, GFP_KERNEL);
27 + char *p_args, *orig;
28
29 + p_args = orig = kmalloc(size, GFP_KERNEL);
30 /* Safe string copys as buf is const */
31 if (!p_args) {
32 dev_warn(device,
33 @@ -1611,7 +1612,7 @@ static ssize_t alarms_store(struct devic
34
35 free_m:
36 /* free allocated memory */
37 - kfree(p_args);
38 + kfree(orig);
39
40 return size;
41 }