Re: [PATCH] regulator: rt4801: Fix NULL pointer dereference if priv->enable_gpios is NULL

From: Axel Lin
Date: Thu Jun 03 2021 - 07:22:36 EST


cy_huang(黃啟原) <cy_huang@xxxxxxxxxxx> 於 2021年6月3日 週四 下午6:39寫道:
>
> Hi, Axel:
>
> Which case will cause this error? I'm not really sure.
> But if devm_gpiod_get_array_optional will return null, then it must be check
> earlier in probe function
>
> priv->enable_gpios = devm_gpiod_get_array_optional(&i2c->dev, "enable",
> GPIOD_OUT_HIGH);
> - if (IS_ERR(priv->enable_gpios)) {+ if (IS_ERR_OR_NULL(priv->enable_gpios)) {
>
> If so, this change will be more reasonable.
> Cause in binding document, I already write the min item must be '1'.

Documentation/devicetree/bindings/regulator/richtek,rt4801-regulator.yaml
enable-gpios:
description: GPIOs to use to enable DSVP/DSVN regulator.
The first one is ENP to enable DSVP, and second one is ENM to enable DSVN.
Number of GPIO in the array list could be 1 or 2.
If only one gpio is specified, only one gpio used to control ENP/ENM.
Else both are spefied, DSVP/DSVN could be controlled individually.
Othersie, this property not specified. treat both as always-on regulator.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this imply it's optional.

If it's cannot be optional, you should use devm_gpiod_get_array() instead.

Regards,
Axel