Skip to contentSkip to conversation

drm: bridge: it66121: fix an error code in it66121_probe()

PATCH In review Dan Carpenter 2 participants 4 messages May 15, 2021 – May 17, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm: bridge: it66121: fix an error code in it66121_probe()

This code is passing the wrong variable to PTR_ERR() so it doesn't return the correct error code.

Fixes 988156dc2fc9 ("drm: bridge: add it66121 driver")
---
 drivers/gpu/drm/bridge/ite-it66121.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ite-it66121.c +1 -1
index d8a60691fd32..6980c9801d0d 100644
@@ -943,7 +943,7 @@ static int it66121_probe(struct i2c_client *client,
 	ctx->regmap = devm_regmap_init_i2c(client, &it66121_regmap_config);
 	if (IS_ERR(ctx->regmap)) {
 		ite66121_power_off(ctx);
-		return PTR_ERR(ctx);
+		return PTR_ERR(ctx->regmap);
 	}
 
 	regmap_read(ctx->regmap, IT66121_VENDOR_ID0_REG, &vendor_ids[0]);
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 drm: bridge: it66121: fix a resource leak in probe

In the original code if the "ctx = devm_kzalloc()" allocation failed then we should have called of_node_put(ep); before returning. It's actually a bit easier to do the allocation first before assigning ep = of_graph_get_endpoint_by_regs().

Fixes 988156dc2fc9 ("drm: bridge: add it66121 driver")
---
 drivers/gpu/drm/bridge/ite-it66121.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/ite-it66121.c +4 -4
index 6980c9801d0d..7149ed40af83 100644
@@ -898,14 +898,14 @@ static int it66121_probe(struct i2c_client *client,
 		return -ENXIO;
 	}
 
-	ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
-	if (!ep)
-		return -EINVAL;
-
 	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
 	if (!ctx)
 		return -ENOMEM;
 
+	ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
+	if (!ep)
+		return -EINVAL;
+
 	ctx->dev = dev;
 	ctx->client = client;
 
Signature · 1 line
2.30.2
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm: bridge: it66121: fix a resource leak in probe

Quoted 25 lines · Dan Carpenter

In the original code if the "ctx = devm_kzalloc()" allocation failed then we should have called of_node_put(ep); before returning. It's actually a bit easier to do the allocation first before assigning ep = of_graph_get_endpoint_by_regs().

Fixes 988156dc2fc9 ("drm: bridge: add it66121 driver")
---
 drivers/gpu/drm/bridge/ite-it66121.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/ite-it66121.c +0 -4
index 6980c9801d0d..7149ed40af83 100644
@@ -898,14 +898,14 @@ static int it66121_probe(struct i2c_client *client,
 		return -ENXIO;
 	}
 
-	ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
-	if (!ep)
-		return -EINVAL;
-
 	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);

drivers/gpu/drm/bridge/ite-it66121.c static int it66121_probe(struct i2c_client *client, · line 911

Quoted 10 lines
drivers/gpu/drm/bridge/ite-it66121.c +4 -0
 	if (!ctx)
 		return -ENOMEM;
 
+	ep = of_graph_get_endpoint_by_regs(dev->of_node, 0, 0);
+	if (!ep)
+		return -EINVAL;
+
 	ctx->dev = dev;
 	ctx->client = client;
 

Thanks !

Applying to drm-misc-fixes

Acked-by on v1 1/2
#3 lore raw
In reply to Dan Carpenter
Quoted 15 lines · Dan Carpenter

This code is passing the wrong variable to PTR_ERR() so it doesn't return the correct error code.

Fixes 988156dc2fc9 ("drm: bridge: add it66121 driver")
---
 drivers/gpu/drm/bridge/ite-it66121.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/ite-it66121.c +0 -0
index d8a60691fd32..6980c9801d0d 100644

drivers/gpu/drm/bridge/ite-it66121.c static int it66121_probe(struct i2c_client *client, · line 949

Quoted 8 lines
drivers/gpu/drm/bridge/ite-it66121.c +1 -1
@@ -943,7 +943,7 @@ static int it66121_probe(struct i2c_client *client,
 	ctx->regmap = devm_regmap_init_i2c(client, &it66121_regmap_config);
 	if (IS_ERR(ctx->regmap)) {
 		ite66121_power_off(ctx);
-		return PTR_ERR(ctx);
+		return PTR_ERR(ctx->regmap);
 	}
 
 	regmap_read(ctx->regmap, IT66121_VENDOR_ID0_REG, &vendor_ids[0]);

Thanks !

Applying to drm-misc-fixes