* [PATCH] sound: codecs: fix a potential NULL pointer dereference
@ 2019-03-24 23:12 Kangjie Lu
2019-03-25 6:45 ` Mukesh Ojha
0 siblings, 1 reply; 4+ messages in thread
From: Kangjie Lu @ 2019-03-24 23:12 UTC (permalink / raw)
To: kjlu
Cc: pakki001, Bard Liao, Oder Chiou, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel
In case devm_kzalloc fails, the patch returns -ENOMEM to avoid
potential NULL pointer dereference.
Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
sound/soc/codecs/rt5663.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/soc/codecs/rt5663.c b/sound/soc/codecs/rt5663.c
index da6647015708..909ab99a1995 100644
--- a/sound/soc/codecs/rt5663.c
+++ b/sound/soc/codecs/rt5663.c
@@ -3480,6 +3480,8 @@ static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
table_size = sizeof(struct impedance_mapping_table) *
rt5663->pdata.impedance_sensing_num;
rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
+ if (!rt5663->imp_table)
+ return -ENOMEM;
device_property_read_u32_array(dev,
"realtek,impedance_sensing_table",
(u32 *)rt5663->imp_table, table_size);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] sound: codecs: fix a potential NULL pointer dereference
2019-03-24 23:12 [PATCH] sound: codecs: fix a potential NULL pointer dereference Kangjie Lu
@ 2019-03-25 6:45 ` Mukesh Ojha
2019-03-25 6:54 ` Mukesh Ojha
2019-03-25 21:19 ` [PATCH v2] " Kangjie Lu
0 siblings, 2 replies; 4+ messages in thread
From: Mukesh Ojha @ 2019-03-25 6:45 UTC (permalink / raw)
To: Kangjie Lu
Cc: pakki001, Bard Liao, Oder Chiou, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel
On 3/25/2019 4:42 AM, Kangjie Lu wrote:
> In case devm_kzalloc fails, the patch returns -ENOMEM to avoid
> potential NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
> sound/soc/codecs/rt5663.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/sound/soc/codecs/rt5663.c b/sound/soc/codecs/rt5663.c
> index da6647015708..909ab99a1995 100644
> --- a/sound/soc/codecs/rt5663.c
> +++ b/sound/soc/codecs/rt5663.c
> @@ -3480,6 +3480,8 @@ static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
> table_size = sizeof(struct impedance_mapping_table) *
> rt5663->pdata.impedance_sensing_num;
> rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
> + if (!rt5663->imp_table)
> + return -ENOMEM;
add checks in rt5663_parse_dp as well.
Thanks.
Mukesh
> device_property_read_u32_array(dev,
> "realtek,impedance_sensing_table",
> (u32 *)rt5663->imp_table, table_size);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] sound: codecs: fix a potential NULL pointer dereference
2019-03-25 6:45 ` Mukesh Ojha
@ 2019-03-25 6:54 ` Mukesh Ojha
2019-03-25 21:19 ` [PATCH v2] " Kangjie Lu
1 sibling, 0 replies; 4+ messages in thread
From: Mukesh Ojha @ 2019-03-25 6:54 UTC (permalink / raw)
To: Kangjie Lu
Cc: pakki001, Bard Liao, Oder Chiou, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel
Hi Kangjje/Aditya,
Please do take care of the return value you are sending upstream whether
still is checked or not
otherwise NULL pointer dereference will still come.
Also resource release properly otherwise your patch may looks simple but
it can introduce memory leak as well in other path.
Thanks,
Mukesh
On 3/25/2019 12:15 PM, Mukesh Ojha wrote:
>
> On 3/25/2019 4:42 AM, Kangjie Lu wrote:
>> In case devm_kzalloc fails, the patch returns -ENOMEM to avoid
>> potential NULL pointer dereference.
>>
>> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
>> ---
>> sound/soc/codecs/rt5663.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/sound/soc/codecs/rt5663.c b/sound/soc/codecs/rt5663.c
>> index da6647015708..909ab99a1995 100644
>> --- a/sound/soc/codecs/rt5663.c
>> +++ b/sound/soc/codecs/rt5663.c
>> @@ -3480,6 +3480,8 @@ static int rt5663_parse_dp(struct rt5663_priv
>> *rt5663, struct device *dev)
>> table_size = sizeof(struct impedance_mapping_table) *
>> rt5663->pdata.impedance_sensing_num;
>> rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
>> + if (!rt5663->imp_table)
>> + return -ENOMEM;
>
> add checks in rt5663_parse_dp as well.
>
> Thanks.
> Mukesh
>
>
>> device_property_read_u32_array(dev,
>> "realtek,impedance_sensing_table",
>> (u32 *)rt5663->imp_table, table_size);
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] sound: codecs: fix a potential NULL pointer dereference
2019-03-25 6:45 ` Mukesh Ojha
2019-03-25 6:54 ` Mukesh Ojha
@ 2019-03-25 21:19 ` Kangjie Lu
1 sibling, 0 replies; 4+ messages in thread
From: Kangjie Lu @ 2019-03-25 21:19 UTC (permalink / raw)
To: kjlu
Cc: pakki001, Bard Liao, Oder Chiou, Liam Girdwood, Mark Brown,
Jaroslav Kysela, Takashi Iwai, alsa-devel, linux-kernel
In case devm_kzalloc fails, the patch returns -ENOMEM to avoid
potential NULL pointer dereference.
Also add a check for rt5663_parse_dp to pass the error code
upstream
Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
---
v2: pass error code upstream in the caller as suggested by
Mukesh Ojha <mojha@codeaurora.org>
---
sound/soc/codecs/rt5663.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/rt5663.c b/sound/soc/codecs/rt5663.c
index da6647015708..ab03ba499ad2 100644
--- a/sound/soc/codecs/rt5663.c
+++ b/sound/soc/codecs/rt5663.c
@@ -3480,6 +3480,8 @@ static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
table_size = sizeof(struct impedance_mapping_table) *
rt5663->pdata.impedance_sensing_num;
rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
+ if (!rt5663->imp_table)
+ return -ENOMEM;
device_property_read_u32_array(dev,
"realtek,impedance_sensing_table",
(u32 *)rt5663->imp_table, table_size);
@@ -3507,8 +3509,11 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
if (pdata)
rt5663->pdata = *pdata;
- else
- rt5663_parse_dp(rt5663, &i2c->dev);
+ else {
+ ret = rt5663_parse_dp(rt5663, &i2c->dev);
+ if (ret)
+ return ret;
+ }
for (i = 0; i < ARRAY_SIZE(rt5663->supplies); i++)
rt5663->supplies[i].supply = rt5663_supply_names[i];
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-25 21:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-24 23:12 [PATCH] sound: codecs: fix a potential NULL pointer dereference Kangjie Lu
2019-03-25 6:45 ` Mukesh Ojha
2019-03-25 6:54 ` Mukesh Ojha
2019-03-25 21:19 ` [PATCH v2] " Kangjie Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).