[PATCH 1/2] ASoC: tlv320adcx140: Avoid accessing invalid gpio_reset

Dan Murphy dmurphy at ti.com
Tue Sep 8 13:55:44 CEST 2020


Camel

On 9/8/20 3:35 AM, Camel Guo wrote:
> From: Camel Guo <camelg at axis.com>
>
> When gpio_reset is not well defined in devicetree, the
> adcx140->gpio_reset is an error code instead of NULL. In this case,
> adcx140->gpio_reset should not be used by adcx140_reset. This commit
> sets it NULL to avoid accessing an invalid variable.
>
> Signed-off-by: Camel Guo <camelg at axis.com>
> ---
>   sound/soc/codecs/tlv320adcx140.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/codecs/tlv320adcx140.c b/sound/soc/codecs/tlv320adcx140.c
> index 7ae6ec374be3..597dd1062943 100644
> --- a/sound/soc/codecs/tlv320adcx140.c
> +++ b/sound/soc/codecs/tlv320adcx140.c
> @@ -984,8 +984,10 @@ static int adcx140_i2c_probe(struct i2c_client *i2c,
>   
>   	adcx140->gpio_reset = devm_gpiod_get_optional(adcx140->dev,
>   						      "reset", GPIOD_OUT_LOW);
> -	if (IS_ERR(adcx140->gpio_reset))
> +	if (IS_ERR(adcx140->gpio_reset) || adcx140->gpio_reset == NULL) {

This looks a bit off and seems like the NULL check was added just to 
print the message.

I would suggest removing the "or" check and just set the gpio_reset to 
NULL in an error case.

This avoids noise in the log especially if the gpio_reset is 
intentionally not populated in the DT

Dan



More information about the Alsa-devel mailing list