2018-02-22 18:10:04

by Colin King

[permalink] [raw]
Subject: [PATCH] MIPS: OCTEON: irq: check for null return on kzalloc allocation

From: Colin Ian King <[email protected]>

The allocation of host_data is not null checked, leading to a
null pointer dereference if the allocation fails. Fix this by
adding a null check and return with -ENOMEM.

Fixes: 64b139f97c01 ("MIPS: OCTEON: irq: add CIB and other fixes")
Signed-off-by: Colin Ian King <[email protected]>
---
arch/mips/cavium-octeon/octeon-irq.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
index b993d9f2c9b9..203e1d2a56d5 100644
--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -2277,6 +2277,8 @@ static int __init octeon_irq_init_cib(struct device_node *ciu_node,
}

host_data = kzalloc(sizeof(*host_data), GFP_KERNEL);
+ if (!host_data)
+ return -ENOMEM;
raw_spin_lock_init(&host_data->lock);

addr = of_get_address(ciu_node, 0, NULL, NULL);
--
2.15.1



2018-02-22 18:11:56

by David Daney

[permalink] [raw]
Subject: Re: [PATCH] MIPS: OCTEON: irq: check for null return on kzalloc allocation

On 02/22/2018 10:08 AM, Colin King wrote:
> From: Colin Ian King <[email protected]>
>
> The allocation of host_data is not null checked, leading to a
> null pointer dereference if the allocation fails. Fix this by
> adding a null check and return with -ENOMEM.
>
> Fixes: 64b139f97c01 ("MIPS: OCTEON: irq: add CIB and other fixes")
> Signed-off-by: Colin Ian King <[email protected]>

Acked-by: David Daney <[email protected]>


> ---
> arch/mips/cavium-octeon/octeon-irq.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
> index b993d9f2c9b9..203e1d2a56d5 100644
> --- a/arch/mips/cavium-octeon/octeon-irq.c
> +++ b/arch/mips/cavium-octeon/octeon-irq.c
> @@ -2277,6 +2277,8 @@ static int __init octeon_irq_init_cib(struct device_node *ciu_node,
> }
>
> host_data = kzalloc(sizeof(*host_data), GFP_KERNEL);
> + if (!host_data)
> + return -ENOMEM;
> raw_spin_lock_init(&host_data->lock);
>
> addr = of_get_address(ciu_node, 0, NULL, NULL);
>


2018-02-23 09:54:14

by James Hogan

[permalink] [raw]
Subject: Re: [PATCH] MIPS: OCTEON: irq: check for null return on kzalloc allocation

On Thu, Feb 22, 2018 at 10:10:30AM -0800, David Daney wrote:
> On 02/22/2018 10:08 AM, Colin King wrote:
> > From: Colin Ian King <[email protected]>
> >
> > The allocation of host_data is not null checked, leading to a
> > null pointer dereference if the allocation fails. Fix this by
> > adding a null check and return with -ENOMEM.
> >
> > Fixes: 64b139f97c01 ("MIPS: OCTEON: irq: add CIB and other fixes")
> > Signed-off-by: Colin Ian King <[email protected]>
>
> Acked-by: David Daney <[email protected]>

Applied to my fixes branch with 4.0+ stable tag.

Thanks
James


Attachments:
(No filename) (613.00 B)
signature.asc (849.00 B)
Digital signature
Download all attachments