media: st-mipid02: add a check for devm_gpiod_get_optional
Subsystems (2)
PATCH 1/1 media: st-mipid02: add a check for devm_gpiod_get_optional
mipid02_probe misses a check for devm_gpiod_get_optional and may miss the failure.
Add a check to fix the problem.
--- drivers/media/i2c/st-mipid02.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/i2c/st-mipid02.c +3 -0
@@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client) bridge->reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (bridge->reset_gpio)) +return PTR_ERR (bridge->reset_gpio); + ret =mipid02_get_regulators (bridge);if (ret) {dev_err (dev,"failed to get regulators %d" , ret);
Signature · 1 line
2.20.1
Hello Chuhong,
Is this check necessary ?
since looking into code it seems to me devm_gpiod_get_optional() can only return NULL in case of error due to following check in devm_gpiod_get_index_optional()
if (IS_ERR(desc)) {
if (PTR_ERR(desc) == -ENOENT)
return NULL;
} And in that case reset_gpio is not used
Regards
Mickael
Quoted 24 lines · Chuhong Yuan
mipid02_probemisses a check fordevm_gpiod_get_optionaland may miss the failure.
Add a check to fix the problem.Signed-off-by Chuhong Yuan <[email protected]>--- drivers/media/i2c/st-mipid02.c | 3 +++ 1 file changed, 3 insertions(+)drivers/media/i2c/st-mipid02.c +3
-0@@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client) bridge->reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (bridge->reset_gpio)) +return PTR_ERR (bridge->reset_gpio); + ret =mipid02_get_regulators (bridge);if (ret) {dev_err (dev,"failed to get regulators %d" , ret);
Quoted 12 lines · Mickael GUENE
Hello Chuhong,
Is this check necessary ?
since looking into code it seems to medevm_gpiod_get_optional()can only return NULL in case of error due to following check indevm_gpiod_get_index_optional()if (IS_ERR(desc)) { if (PTR_ERR(desc) == -ENOENT) return NULL; }And in that case
reset_gpiois not used
The problem may not be a null return value, but a returned error, which is a minus value,
like -EPROBE_DEFER or -EINVAL returned by gpiod_find in gpiod_get_index. In these cases, devm_gpiod_get_index_optional will not return null but return the error.
Therefore, this check is necessary.
Quoted 28 lines
Regards
MickaelQuoted 24 lines · Chuhong Yuan
mipid02_probemisses a check fordevm_gpiod_get_optionaland may miss the failure.
Add a check to fix the problem.Signed-off-by Chuhong Yuan <[email protected]>--- drivers/media/i2c/st-mipid02.c | 3 +++ 1 file changed, 3 insertions(+)drivers/media/i2c/st-mipid02.c +3
-0@@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client) bridge->reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (bridge->reset_gpio)) +return PTR_ERR (bridge->reset_gpio); + ret =mipid02_get_regulators (bridge);if (ret) {dev_err (dev,"failed to get regulators %d" , ret);
Hello Chuhong,
Sorry I missed 'if (PTR_ERR(desc) == -ENOENT)' check .... Can you in this case add an error message ?
Regards
Mickael
Quoted 49 lines · Chuhong Yuan
Quoted 12 lines · Mickael GUENE
Hello Chuhong,
Is this check necessary ?
since looking into code it seems to medevm_gpiod_get_optional()can only return NULL in case of error due to following check indevm_gpiod_get_index_optional()if (IS_ERR(desc)) { if (PTR_ERR(desc) == -ENOENT) return NULL; }And in that case
reset_gpiois not usedThe problem may not be a null return value, but a returned error, which is a minus value,
like -EPROBE_DEFER or-EINVALreturned bygpiod_findingpiod_get_index. In these cases,devm_gpiod_get_index_optionalwill not return null but return the error.
Therefore, this check is necessary.Quoted 28 lines
Regards
MickaelQuoted 24 lines · Chuhong Yuan
mipid02_probemisses a check fordevm_gpiod_get_optionaland may miss the failure.
Add a check to fix the problem.Signed-off-by Chuhong Yuan <[email protected]>--- drivers/media/i2c/st-mipid02.c | 3 +++ 1 file changed, 3 insertions(+)drivers/media/i2c/st-mipid02.c +3
-0@@ -971,6 +971,9 @@ static int mipid02_probe(struct i2c_client *client) bridge->reset_gpio =devm_gpiod_get_optional (dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (bridge->reset_gpio)) +return PTR_ERR (bridge->reset_gpio); + ret =mipid02_get_regulators (bridge);if (ret) {dev_err (dev,"failed to get regulators %d" , ret);