From: Luiz Sampaio <sampaio.ime@gmail.com>
To: ojeda@kernel.org
Cc: linux-kernel@vger.kernel.org, Luiz Sampaio <sampaio.ime@gmail.com>
Subject: [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing
Date: Tue, 9 Nov 2021 19:07:32 -0300 [thread overview]
Message-ID: <20211109220732.7973-3-sampaio.ime@gmail.com> (raw)
In-Reply-To: <20211109220732.7973-1-sampaio.ime@gmail.com>
Check if the pointer lcd->ops->init_display exists before dereferencing it.
If a driver called charlcd_init() without defining the ops, this would
return segmentation fault, as happened to me when implementing a charlcd
driver. Checking the pointer before dereferencing protects from
segmentation fault.
Signed-off-by: Luiz Sampaio <sampaio.ime@gmail.com>
---
drivers/auxdisplay/charlcd.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c
index cca3b600c0ba..6d309e4971b6 100644
--- a/drivers/auxdisplay/charlcd.c
+++ b/drivers/auxdisplay/charlcd.c
@@ -578,6 +578,9 @@ static int charlcd_init(struct charlcd *lcd)
* Since charlcd_init_display() needs to write data, we have to
* enable mark the LCD initialized just before.
*/
+ if (WARN_ON(!lcd->ops->init_display))
+ return -EINVAL;
+
ret = lcd->ops->init_display(lcd);
if (ret)
return ret;
--
2.33.1
next prev parent reply other threads:[~2021-11-09 22:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-07 15:03 [PATCH 0/2] Fixing bug that would segmentation fault Luiz Sampaio
2021-11-07 15:03 ` [PATCH 1/2] auxdisplay: charlcd: fixing coding style issue Luiz Sampaio
2021-11-08 12:01 ` Miguel Ojeda
2021-11-07 15:03 ` [PATCH 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing Luiz Sampaio
2021-11-08 11:58 ` Miguel Ojeda
2021-11-09 22:07 ` [PATCH v2 0/2] Fixing bug that would segmentation fault Luiz Sampaio
2021-11-09 22:07 ` [PATCH v2 1/2] auxdisplay: charlcd: fixing coding style issue Luiz Sampaio
2021-11-24 11:02 ` Miguel Ojeda
2021-11-09 22:07 ` Luiz Sampaio [this message]
2021-11-24 11:01 ` [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing Miguel Ojeda
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=20211109220732.7973-3-sampaio.ime@gmail.com \
--to=sampaio.ime@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
/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).