sound: codecs: fix a potential NULL pointer dereference
diff mbox series

Message ID 20190324231237.2246-1-kjlu@umn.edu
State New
Headers show
Series
  • sound: codecs: fix a potential NULL pointer dereference
Related show

Commit Message

Kangjie Lu March 24, 2019, 11:12 p.m. UTC
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(+)

Comments

Mukesh Ojha March 25, 2019, 6:45 a.m. UTC | #1
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);
Mukesh Ojha March 25, 2019, 6:54 a.m. UTC | #2
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);

Patch
diff mbox series

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);