From: Salah Triki <salah.triki@gmail.com>
To: Nicolas Ferre <nicolas.ferre@microchip.com>,
Helge Deller <deller@gmx.de>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Beznea <claudiu.beznea@tuxon.dev>,
linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: salah.triki@gmail.com
Subject: [PATCH] fbdev: atmel_lcdfb: Fix potential NULL dereference
Date: Thu, 24 Jul 2025 03:56:45 +0100 [thread overview]
Message-ID: <aIGg7erPjz1qJQ1F@pc> (raw)
of_match_device() returns NULL in case of failure, so check its return
value before casting and accessing to data field in order to prevent NULL
dereference.
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/video/fbdev/atmel_lcdfb.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/video/fbdev/atmel_lcdfb.c b/drivers/video/fbdev/atmel_lcdfb.c
index 9dfbc5310210..b1017ac9c73b 100644
--- a/drivers/video/fbdev/atmel_lcdfb.c
+++ b/drivers/video/fbdev/atmel_lcdfb.c
@@ -922,6 +922,7 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
struct device *dev = &sinfo->pdev->dev;
struct device_node *np =dev->of_node;
struct device_node *display_np;
+ const struct of_device_id *match;
struct atmel_lcdfb_power_ctrl_gpio *og;
bool is_gpio_power = false;
struct fb_videomode fb_vm;
@@ -930,8 +931,11 @@ static int atmel_lcdfb_of_init(struct atmel_lcdfb_info *sinfo)
int ret;
int i;
- sinfo->config = (struct atmel_lcdfb_config*)
- of_match_device(atmel_lcdfb_dt_ids, dev)->data;
+ match = of_match_device(atmel_lcdfb_dt_ids, dev);
+ if (!match)
+ return -ENODEV;
+
+ sinfo->config = (struct atmel_lcdfb_config *)match->data;
display_np = of_parse_phandle(np, "display", 0);
if (!display_np) {
--
2.43.0
next reply other threads:[~2025-07-24 3:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 2:56 Salah Triki [this message]
2025-07-24 7:29 ` [PATCH] fbdev: atmel_lcdfb: Fix potential NULL dereference Alexandre Belloni
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=aIGg7erPjz1qJQ1F@pc \
--to=salah.triki@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.ferre@microchip.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).