Linux I2C development
 help / color / mirror / Atom feed
* [PATCH RESEND] i2c: mux: reg: check return value after calling platform_get_resource()
@ 2022-10-29  9:38 Yang Yingliang
  2022-12-07 20:21 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-10-29  9:38 UTC (permalink / raw)
  To: linux-i2c; +Cc: peda, yorksun, alexander.sverdlin, wsa, yangyingliang

It will cause null-ptr-deref in resource_size(), if platform_get_resource()
returns NULL, move calling resource_size() after devm_ioremap_resource() that
will check 'res' to avoid null-ptr-deref.
And use devm_platform_get_and_ioremap_resource() to simplify code.

Fixes: b3fdd32799d8 ("i2c: mux: Add register-based mux i2c-mux-reg")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
The previous link:
https://lore.kernel.org/lkml/20220425090509.2524814-1-yangyingliang@huawei.com/
---
 drivers/i2c/muxes/i2c-mux-reg.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c
index 0e0679f65cf7..30a6de1694e0 100644
--- a/drivers/i2c/muxes/i2c-mux-reg.c
+++ b/drivers/i2c/muxes/i2c-mux-reg.c
@@ -183,13 +183,12 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)
 	if (!mux->data.reg) {
 		dev_info(&pdev->dev,
 			"Register not set, using platform resource\n");
-		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-		mux->data.reg_size = resource_size(res);
-		mux->data.reg = devm_ioremap_resource(&pdev->dev, res);
+		mux->data.reg = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
 		if (IS_ERR(mux->data.reg)) {
 			ret = PTR_ERR(mux->data.reg);
 			goto err_put_parent;
 		}
+		mux->data.reg_size = resource_size(res);
 	}
 
 	if (mux->data.reg_size != 4 && mux->data.reg_size != 2 &&
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RESEND] i2c: mux: reg: check return value after calling platform_get_resource()
  2022-10-29  9:38 [PATCH RESEND] i2c: mux: reg: check return value after calling platform_get_resource() Yang Yingliang
@ 2022-12-07 20:21 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2022-12-07 20:21 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-i2c, peda, yorksun, alexander.sverdlin

[-- Attachment #1: Type: text/plain, Size: 622 bytes --]

On Sat, Oct 29, 2022 at 05:38:25PM +0800, Yang Yingliang wrote:
> It will cause null-ptr-deref in resource_size(), if platform_get_resource()
> returns NULL, move calling resource_size() after devm_ioremap_resource() that
> will check 'res' to avoid null-ptr-deref.
> And use devm_platform_get_and_ioremap_resource() to simplify code.
> 
> Fixes: b3fdd32799d8 ("i2c: mux: Add register-based mux i2c-mux-reg")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>

Applied to for-next, thanks!

Peter, as other people are sending similar patches, I applied this one
now right away. Hope you don't mind.


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-07 20:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-29  9:38 [PATCH RESEND] i2c: mux: reg: check return value after calling platform_get_resource() Yang Yingliang
2022-12-07 20:21 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox