2021-12-22 08:34:02

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH] drm/bridge: anx7625: Fix null vs IS_ERR() checking in anx7625_register_i2c_dummy_clients

Since i2c_new_client_device() function return error pointers.
The i2c_new_dummy_device() function does not return NULL, It returns error
pointers too. Using IS_ERR() to check the return value to fix this.

Fixes: 8bdfc5dae4e3("drm/bridge: anx7625: Add anx7625 MIPI DSI/DPI to DP")
Signed-off-by: Miaoqian Lin <[email protected]>
---
drivers/gpu/drm/bridge/analogix/anx7625.c | 32 ++++++++++++++++-------
1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 1a871f6b6822..eb72aa6aedd6 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1637,40 +1637,54 @@ static const struct drm_bridge_funcs anx7625_bridge_funcs = {
static int anx7625_register_i2c_dummy_clients(struct anx7625_data *ctx,
struct i2c_client *client)
{
+ int err = 0;
+
ctx->i2c.tx_p0_client = i2c_new_dummy_device(client->adapter,
TX_P0_ADDR >> 1);
- if (!ctx->i2c.tx_p0_client)
- return -ENOMEM;
+ if (IS_ERR(ctx->i2c.tx_p0_client))
+ return PTR_ERR(ctx->i2c.tx_p0_client);

ctx->i2c.tx_p1_client = i2c_new_dummy_device(client->adapter,
TX_P1_ADDR >> 1);
- if (!ctx->i2c.tx_p1_client)
+ if (IS_ERR(ctx->i2c.tx_p1_client)) {
+ err = PTR_ERR(ctx->i2c.tx_p1_client);
goto free_tx_p0;
+ }

ctx->i2c.tx_p2_client = i2c_new_dummy_device(client->adapter,
TX_P2_ADDR >> 1);
- if (!ctx->i2c.tx_p2_client)
+ if (IS_ERR(ctx->i2c.tx_p2_client)) {
+ err = PTR_ERR(ctx->i2c.tx_p2_client);
goto free_tx_p1;
+ }

ctx->i2c.rx_p0_client = i2c_new_dummy_device(client->adapter,
RX_P0_ADDR >> 1);
- if (!ctx->i2c.rx_p0_client)
+ if (IS_ERR(ctx->i2c.rx_p0_client)) {
+ err = PTR_ERR(ctx->i2c.rx_p0_client);
goto free_tx_p2;
+ }

ctx->i2c.rx_p1_client = i2c_new_dummy_device(client->adapter,
RX_P1_ADDR >> 1);
- if (!ctx->i2c.rx_p1_client)
+ if (IS_ERR(ctx->i2c.rx_p1_client)) {
+ err = PTR_ERR(ctx->i2c.rx_p1_client);
goto free_rx_p0;
+ }

ctx->i2c.rx_p2_client = i2c_new_dummy_device(client->adapter,
RX_P2_ADDR >> 1);
- if (!ctx->i2c.rx_p2_client)
+ if (IS_ERR(ctx->i2c.rx_p2_client)) {
+ err = PTR_ERR(ctx->i2c.rx_p2_client);
goto free_rx_p1;
+ }

ctx->i2c.tcpc_client = i2c_new_dummy_device(client->adapter,
TCPC_INTERFACE_ADDR >> 1);
- if (!ctx->i2c.tcpc_client)
+ if (IS_ERR(ctx->i2c.tcpc_client)) {
+ err = PTR_ERR(ctx->i2c.tcpc_client);
goto free_rx_p2;
+ }

return 0;

@@ -1687,7 +1701,7 @@ static int anx7625_register_i2c_dummy_clients(struct anx7625_data *ctx,
free_tx_p0:
i2c_unregister_device(ctx->i2c.tx_p0_client);

- return -ENOMEM;
+ return err;
}

static void anx7625_unregister_i2c_dummy_clients(struct anx7625_data *ctx)
--
2.17.1



2022-01-04 14:29:16

by Robert Foss

[permalink] [raw]
Subject: Re: [PATCH] drm/bridge: anx7625: Fix null vs IS_ERR() checking in anx7625_register_i2c_dummy_clients

Hey Miaoqian,

Thanks for submitting this fix.

On Wed, 22 Dec 2021 at 09:33, Miaoqian Lin <[email protected]> wrote:
>
> Since i2c_new_client_device() function return error pointers.
> The i2c_new_dummy_device() function does not return NULL, It returns error
> pointers too. Using IS_ERR() to check the return value to fix this.
>
> Fixes: 8bdfc5dae4e3("drm/bridge: anx7625: Add anx7625 MIPI DSI/DPI to DP")
> Signed-off-by: Miaoqian Lin <[email protected]>
> ---
> drivers/gpu/drm/bridge/analogix/anx7625.c | 32 ++++++++++++++++-------
> 1 file changed, 23 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 1a871f6b6822..eb72aa6aedd6 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -1637,40 +1637,54 @@ static const struct drm_bridge_funcs anx7625_bridge_funcs = {
> static int anx7625_register_i2c_dummy_clients(struct anx7625_data *ctx,
> struct i2c_client *client)
> {
> + int err = 0;
> +
> ctx->i2c.tx_p0_client = i2c_new_dummy_device(client->adapter,
> TX_P0_ADDR >> 1);
> - if (!ctx->i2c.tx_p0_client)
> - return -ENOMEM;
> + if (IS_ERR(ctx->i2c.tx_p0_client))
> + return PTR_ERR(ctx->i2c.tx_p0_client);
>
> ctx->i2c.tx_p1_client = i2c_new_dummy_device(client->adapter,
> TX_P1_ADDR >> 1);
> - if (!ctx->i2c.tx_p1_client)
> + if (IS_ERR(ctx->i2c.tx_p1_client)) {
> + err = PTR_ERR(ctx->i2c.tx_p1_client);
> goto free_tx_p0;
> + }
>
> ctx->i2c.tx_p2_client = i2c_new_dummy_device(client->adapter,
> TX_P2_ADDR >> 1);
> - if (!ctx->i2c.tx_p2_client)
> + if (IS_ERR(ctx->i2c.tx_p2_client)) {
> + err = PTR_ERR(ctx->i2c.tx_p2_client);
> goto free_tx_p1;
> + }
>
> ctx->i2c.rx_p0_client = i2c_new_dummy_device(client->adapter,
> RX_P0_ADDR >> 1);
> - if (!ctx->i2c.rx_p0_client)
> + if (IS_ERR(ctx->i2c.rx_p0_client)) {
> + err = PTR_ERR(ctx->i2c.rx_p0_client);
> goto free_tx_p2;
> + }
>
> ctx->i2c.rx_p1_client = i2c_new_dummy_device(client->adapter,
> RX_P1_ADDR >> 1);
> - if (!ctx->i2c.rx_p1_client)
> + if (IS_ERR(ctx->i2c.rx_p1_client)) {
> + err = PTR_ERR(ctx->i2c.rx_p1_client);
> goto free_rx_p0;
> + }
>
> ctx->i2c.rx_p2_client = i2c_new_dummy_device(client->adapter,
> RX_P2_ADDR >> 1);
> - if (!ctx->i2c.rx_p2_client)
> + if (IS_ERR(ctx->i2c.rx_p2_client)) {
> + err = PTR_ERR(ctx->i2c.rx_p2_client);
> goto free_rx_p1;
> + }
>
> ctx->i2c.tcpc_client = i2c_new_dummy_device(client->adapter,
> TCPC_INTERFACE_ADDR >> 1);
> - if (!ctx->i2c.tcpc_client)
> + if (IS_ERR(ctx->i2c.tcpc_client)) {
> + err = PTR_ERR(ctx->i2c.tcpc_client);
> goto free_rx_p2;
> + }
>
> return 0;
>
> @@ -1687,7 +1701,7 @@ static int anx7625_register_i2c_dummy_clients(struct anx7625_data *ctx,
> free_tx_p0:
> i2c_unregister_device(ctx->i2c.tx_p0_client);
>
> - return -ENOMEM;
> + return err;
> }
>
> static void anx7625_unregister_i2c_dummy_clients(struct anx7625_data *ctx)
> --
> 2.17.1
>

Reviewed-by: Robert Foss <[email protected]>