linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_fintek: Fix potential NULL pointer dereference
@ 2016-06-28  1:46 Ji-Ze Hong (Peter Hong)
  2016-08-18 16:22 ` Ricardo Ribalda Delgado
  0 siblings, 1 reply; 2+ messages in thread
From: Ji-Ze Hong (Peter Hong) @ 2016-06-28  1:46 UTC (permalink / raw)
  To: gregkh, jslaby, ricardo.ribalda
  Cc: alan, peter, tom_tsai, peter_hong, linux-serial, linux-kernel,
	Ji-Ze Hong (Peter Hong)

Fix potential NULL pointer dereference on
'commit 4da22f1418cb ("serial: 8250_fintek: fix the mismatched IRQ mode")'

We try to fix IRQ mode mismatch issue and add the following code to
detect IRQ Level or Edge mode.

struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
bool level_mode = irqd_is_level_type(irq_data);

But *irq_data had not any check and pass to irqd_is_level_type(),
it may lead to potential NULL pointer dereference.

Also modify detecting IRQ mode when fintek chip found.

Suggested-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>
---
 drivers/tty/serial/8250/8250_fintek.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
index 737b4b3..9119d0c 100644
--- a/drivers/tty/serial/8250/8250_fintek.c
+++ b/drivers/tty/serial/8250/8250_fintek.c
@@ -212,8 +212,8 @@ int fintek_8250_probe(struct uart_8250_port *uart)
 {
 	struct fintek_8250 *pdata;
 	struct fintek_8250 probe_data;
-	struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
-	bool level_mode = irqd_is_level_type(irq_data);
+	struct irq_data *irq_data;
+	bool level_mode = false; /* Default to Edge/High */
 
 	if (find_base_port(&probe_data, uart->port.iobase))
 		return -ENODEV;
@@ -226,5 +226,14 @@ int fintek_8250_probe(struct uart_8250_port *uart)
 	uart->port.rs485_config = fintek_8250_rs485_config;
 	uart->port.private_data = pdata;
 
+	irq_data = irq_get_irq_data(uart->port.irq);
+	if (irq_data) {
+		level_mode = irqd_is_level_type(irq_data);
+	} else {
+		dev_warn(uart->port.dev,
+			 "%s: Can't get irq_data, set this port to Edge/High",
+			 __func__);
+	}
+
 	return fintek_8250_set_irq_mode(pdata, level_mode);
 }
-- 
1.9.1

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

* Re: [PATCH] serial: 8250_fintek: Fix potential NULL pointer dereference
  2016-06-28  1:46 [PATCH] serial: 8250_fintek: Fix potential NULL pointer dereference Ji-Ze Hong (Peter Hong)
@ 2016-08-18 16:22 ` Ricardo Ribalda Delgado
  0 siblings, 0 replies; 2+ messages in thread
From: Ricardo Ribalda Delgado @ 2016-08-18 16:22 UTC (permalink / raw)
  To: Ji-Ze Hong (Peter Hong)
  Cc: Greg Kroah-Hartman, Jiri Slaby, Alan Cox, Peter Hurley,
	PA20 TOM TSAI 蔡宗佑,
	Peter H, linux-serial, LKML, Ji-Ze Hong (Peter Hong)

Hi Peter

Somehow this patch entered my mail limbo. Sorry about that.

Could you remove the brackets on the if/else? I think that for one
liners they are not recommended.

Also, I think it might be a good a idea to remove the __func__ from
the dev_warn.

Best regards!



On Tue, Jun 28, 2016 at 3:46 AM, Ji-Ze Hong (Peter Hong)
<hpeter@gmail.com> wrote:
> Fix potential NULL pointer dereference on
> 'commit 4da22f1418cb ("serial: 8250_fintek: fix the mismatched IRQ mode")'
>
> We try to fix IRQ mode mismatch issue and add the following code to
> detect IRQ Level or Edge mode.
>
> struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
> bool level_mode = irqd_is_level_type(irq_data);
>
> But *irq_data had not any check and pass to irqd_is_level_type(),
> it may lead to potential NULL pointer dereference.
>
> Also modify detecting IRQ mode when fintek chip found.
>
> Suggested-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
> Signed-off-by: Ji-Ze Hong (Peter Hong) <hpeter+linux_kernel@gmail.com>
> ---
>  drivers/tty/serial/8250/8250_fintek.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_fintek.c b/drivers/tty/serial/8250/8250_fintek.c
> index 737b4b3..9119d0c 100644
> --- a/drivers/tty/serial/8250/8250_fintek.c
> +++ b/drivers/tty/serial/8250/8250_fintek.c
> @@ -212,8 +212,8 @@ int fintek_8250_probe(struct uart_8250_port *uart)
>  {
>         struct fintek_8250 *pdata;
>         struct fintek_8250 probe_data;
> -       struct irq_data *irq_data = irq_get_irq_data(uart->port.irq);
> -       bool level_mode = irqd_is_level_type(irq_data);
> +       struct irq_data *irq_data;
> +       bool level_mode = false; /* Default to Edge/High */
>
>         if (find_base_port(&probe_data, uart->port.iobase))
>                 return -ENODEV;
> @@ -226,5 +226,14 @@ int fintek_8250_probe(struct uart_8250_port *uart)
>         uart->port.rs485_config = fintek_8250_rs485_config;
>         uart->port.private_data = pdata;
>
> +       irq_data = irq_get_irq_data(uart->port.irq);
> +       if (irq_data) {
> +               level_mode = irqd_is_level_type(irq_data);
> +       } else {
> +               dev_warn(uart->port.dev,
> +                        "%s: Can't get irq_data, set this port to Edge/High",
> +                        __func__);
> +       }
> +
>         return fintek_8250_set_irq_mode(pdata, level_mode);
>  }
> --
> 1.9.1
>



-- 
Ricardo Ribalda

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

end of thread, other threads:[~2016-08-19  1:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-28  1:46 [PATCH] serial: 8250_fintek: Fix potential NULL pointer dereference Ji-Ze Hong (Peter Hong)
2016-08-18 16:22 ` Ricardo Ribalda Delgado

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).