From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@redhat.com, jfalempe@redhat.com, daniel@ffwll.ch
Cc: Thomas Zimmermann <tzimmermann@suse.de>, dri-devel@lists.freedesktop.org
Subject: [PATCH] drm/mgag200: Fail on I2C initialization errors
Date: Thu, 5 May 2022 17:22:44 +0200 [thread overview]
Message-ID: <20220505152244.413-1-tzimmermann@suse.de> (raw)
Initialization of the I2C adapter was allowed to fail. The mgag200
driver would have continued without DDC support. Had this happened in
practice, it would have led to segmentation faults in the connector
code. Resolve this problem by failing driver initialization on I2C-
related errors.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
drivers/gpu/drm/mgag200/mgag200_i2c.c | 13 ++++++++-----
drivers/gpu/drm/mgag200/mgag200_mode.c | 6 ++++--
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/mgag200/mgag200_i2c.c b/drivers/gpu/drm/mgag200/mgag200_i2c.c
index ac8e34eef5138..31e2c641a7814 100644
--- a/drivers/gpu/drm/mgag200/mgag200_i2c.c
+++ b/drivers/gpu/drm/mgag200/mgag200_i2c.c
@@ -120,7 +120,7 @@ struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev)
i2c = kzalloc(sizeof(struct mga_i2c_chan), GFP_KERNEL);
if (!i2c)
- return NULL;
+ return ERR_PTR(-ENOMEM);
i2c->data = data;
i2c->clock = clock;
@@ -142,11 +142,14 @@ struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev)
i2c->bit.getscl = mga_gpio_getscl;
ret = i2c_bit_add_bus(&i2c->adapter);
- if (ret) {
- kfree(i2c);
- i2c = NULL;
- }
+ if (ret)
+ goto err_kfree;
+
return i2c;
+
+err_kfree:
+ kfree(i2c);
+ return ERR_PTR(ret);
}
void mgag200_i2c_destroy(struct mga_i2c_chan *i2c)
diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c
index abde7655477db..79557ca056f08 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -815,8 +815,10 @@ static int mgag200_vga_connector_init(struct mga_device *mdev)
int ret;
i2c = mgag200_i2c_create(dev);
- if (!i2c)
- drm_warn(dev, "failed to add DDC bus\n");
+ if (IS_ERR(i2c)) {
+ drm_err(dev, "failed to add DDC bus: %d\n", ret);
+ return PTR_ERR(i2c);
+ }
ret = drm_connector_init_with_ddc(dev, connector,
&mga_vga_connector_funcs,
--
2.36.0
next reply other threads:[~2022-05-05 15:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 15:22 Thomas Zimmermann [this message]
2022-05-05 15:49 ` [PATCH] drm/mgag200: Fail on I2C initialization errors Jocelyn Falempe
2022-05-06 10:53 ` Thomas Zimmermann
2022-05-05 21:06 ` kernel test robot
2022-05-05 21:06 ` kernel test robot
-- strict thread matches above, loose matches on Subject: below --
2022-05-06 2:25 kernel test robot
2022-05-06 7:26 ` Dan Carpenter
2022-05-06 7:26 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220505152244.413-1-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@redhat.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=jfalempe@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.