LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] Fixing bug that would segmentation fault
@ 2021-11-07 15:03 Luiz Sampaio
2021-11-07 15:03 ` [PATCH 1/2] auxdisplay: charlcd: fixing coding style issue Luiz Sampaio
2021-11-07 15:03 ` [PATCH 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing Luiz Sampaio
0 siblings, 2 replies; 10+ messages in thread
From: Luiz Sampaio @ 2021-11-07 15:03 UTC (permalink / raw)
To: ojeda; +Cc: linux-kernel, Luiz Sampaio
This series of patches consists of one patch fixing a simple coding style
issue and one patch fixing a bug that would cause segmentation fault.
Basically, there was a pointer that was being dereferenced without testing
if the pointer exists. This patch adds a protection, returning EFAULT in
case the pointer is NULL.
Luiz Sampaio (2):
auxdisplay: charlcd: fixing coding style issue
auxdisplay: charlcd: checking for pointer reference before
dereferencing
drivers/auxdisplay/charlcd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
--
2.33.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/2] auxdisplay: charlcd: fixing coding style issue
2021-11-07 15:03 [PATCH 0/2] Fixing bug that would segmentation fault Luiz Sampaio
@ 2021-11-07 15:03 ` 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
1 sibling, 1 reply; 10+ messages in thread
From: Luiz Sampaio @ 2021-11-07 15:03 UTC (permalink / raw)
To: ojeda; +Cc: linux-kernel, Luiz Sampaio
Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
Signed-off-by: Luiz Sampaio <sampaio.ime@gmail.com>
---
drivers/auxdisplay/charlcd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c
index 304accde365c..cca3b600c0ba 100644
--- a/drivers/auxdisplay/charlcd.c
+++ b/drivers/auxdisplay/charlcd.c
@@ -37,7 +37,7 @@ struct charlcd_priv {
bool must_clear;
/* contains the LCD config state */
- unsigned long int flags;
+ unsigned long flags;
/* Current escape sequence and it's length or -1 if outside */
struct {
--
2.33.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing
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-07 15:03 ` Luiz Sampaio
2021-11-08 11:58 ` Miguel Ojeda
1 sibling, 1 reply; 10+ messages in thread
From: Luiz Sampaio @ 2021-11-07 15:03 UTC (permalink / raw)
To: ojeda; +Cc: linux-kernel, Luiz Sampaio
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..47363fb2fe94 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 (!lcd->ops->init_display)
+ return -EFAULT;
+
ret = lcd->ops->init_display(lcd);
if (ret)
return ret;
--
2.33.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing
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
0 siblings, 1 reply; 10+ messages in thread
From: Miguel Ojeda @ 2021-11-08 11:58 UTC (permalink / raw)
To: Luiz Sampaio; +Cc: Miguel Ojeda, linux-kernel
On Sun, Nov 7, 2021 at 4:03 PM Luiz Sampaio <sampaio.ime@gmail.com> wrote:
>
> 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.
It can't hurt -- thanks! I think `EINVAL` makes more sense here, also
we could use `WARN_ON`:
if (WARN_ON(!lcd->ops->init_display))
return -EINVAL;
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] auxdisplay: charlcd: fixing coding style issue
2021-11-07 15:03 ` [PATCH 1/2] auxdisplay: charlcd: fixing coding style issue Luiz Sampaio
@ 2021-11-08 12:01 ` Miguel Ojeda
0 siblings, 0 replies; 10+ messages in thread
From: Miguel Ojeda @ 2021-11-08 12:01 UTC (permalink / raw)
To: Luiz Sampaio; +Cc: Miguel Ojeda, linux-kernel
On Sun, Nov 7, 2021 at 4:03 PM Luiz Sampaio <sampaio.ime@gmail.com> wrote:
>
> Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
Not sure if this is a rule, but it is good to be consistent with the
rest of auxdisplay. Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 0/2] Fixing bug that would segmentation fault
2021-11-08 11:58 ` Miguel Ojeda
@ 2021-11-09 22:07 ` Luiz Sampaio
2021-11-09 22:07 ` [PATCH v2 1/2] auxdisplay: charlcd: fixing coding style issue Luiz Sampaio
2021-11-09 22:07 ` [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing Luiz Sampaio
0 siblings, 2 replies; 10+ messages in thread
From: Luiz Sampaio @ 2021-11-09 22:07 UTC (permalink / raw)
To: ojeda; +Cc: linux-kernel, Luiz Sampaio
This series of patches consists of one patch fixing a simple coding style
issue and one patch fixing a bug that would cause segmentation fault.
Basically, there was a pointer that was being dereferenced without testing
if the pointer exists. This patch adds a protection, returning EFAULT in
case the pointer is NULL.
Changes in v2:
- Changed return to -EINVAL and using WARN_ON as suggested
- Note in response for Miguel's comment: for the first patch, I ran the
script './scripts/checkpatch.pl --file --terse' to see with the file
had any coding style issue. That was when I was suggested to remove
'int' from 'unsigned long' declaration
Luiz Sampaio (2):
auxdisplay: charlcd: fixing coding style issue
auxdisplay: charlcd: checking for pointer reference before
dereferencing
drivers/auxdisplay/charlcd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
--
2.33.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 1/2] auxdisplay: charlcd: fixing coding style issue
2021-11-09 22:07 ` [PATCH v2 0/2] Fixing bug that would segmentation fault Luiz Sampaio
@ 2021-11-09 22:07 ` Luiz Sampaio
2021-11-24 11:02 ` Miguel Ojeda
2021-11-09 22:07 ` [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing Luiz Sampaio
1 sibling, 1 reply; 10+ messages in thread
From: Luiz Sampaio @ 2021-11-09 22:07 UTC (permalink / raw)
To: ojeda; +Cc: linux-kernel, Luiz Sampaio
Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
Signed-off-by: Luiz Sampaio <sampaio.ime@gmail.com>
---
drivers/auxdisplay/charlcd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/auxdisplay/charlcd.c b/drivers/auxdisplay/charlcd.c
index 304accde365c..cca3b600c0ba 100644
--- a/drivers/auxdisplay/charlcd.c
+++ b/drivers/auxdisplay/charlcd.c
@@ -37,7 +37,7 @@ struct charlcd_priv {
bool must_clear;
/* contains the LCD config state */
- unsigned long int flags;
+ unsigned long flags;
/* Current escape sequence and it's length or -1 if outside */
struct {
--
2.33.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing
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-09 22:07 ` Luiz Sampaio
2021-11-24 11:01 ` Miguel Ojeda
1 sibling, 1 reply; 10+ messages in thread
From: Luiz Sampaio @ 2021-11-09 22:07 UTC (permalink / raw)
To: ojeda; +Cc: linux-kernel, Luiz Sampaio
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing
2021-11-09 22:07 ` [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing Luiz Sampaio
@ 2021-11-24 11:01 ` Miguel Ojeda
0 siblings, 0 replies; 10+ messages in thread
From: Miguel Ojeda @ 2021-11-24 11:01 UTC (permalink / raw)
To: Luiz Sampaio; +Cc: Miguel Ojeda, linux-kernel
On Tue, Nov 9, 2021 at 11:07 PM Luiz Sampaio <sampaio.ime@gmail.com> wrote:
>
> 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>
Queued up, thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 1/2] auxdisplay: charlcd: fixing coding style issue
2021-11-09 22:07 ` [PATCH v2 1/2] auxdisplay: charlcd: fixing coding style issue Luiz Sampaio
@ 2021-11-24 11:02 ` Miguel Ojeda
0 siblings, 0 replies; 10+ messages in thread
From: Miguel Ojeda @ 2021-11-24 11:02 UTC (permalink / raw)
To: Luiz Sampaio; +Cc: Miguel Ojeda, linux-kernel
On Tue, Nov 9, 2021 at 11:07 PM Luiz Sampaio <sampaio.ime@gmail.com> wrote:
>
> Removing 'int' from 'unsigned long int' declaration, which is unnecessary.
>
> Signed-off-by: Luiz Sampaio <sampaio.ime@gmail.com>
Queued up, thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-11-24 11:02 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2 2/2] auxdisplay: charlcd: checking for pointer reference before dereferencing Luiz Sampaio
2021-11-24 11:01 ` Miguel Ojeda
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).