linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: Hariprasad Kelam <hariprasad.kelam@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Jason Cooper <jason@lakedaemon.net>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Marc Gonzalez <marc.w.gonzalez@free.fr>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] irqchip/tango: Add NULL check after memory operation
Date: Mon, 22 Jul 2019 09:54:46 +0100	[thread overview]
Message-ID: <yw1xh87efnzd.fsf@mansr.com> (raw)
In-Reply-To: <20190721181536.GA13450@hari-Inspiron-1545> (Hariprasad Kelam's message of "Sun, 21 Jul 2019 23:45:36 +0530")

Hariprasad Kelam <hariprasad.kelam@gmail.com> writes:

> Add NULL check after kzalloc operation.
>
> Fix below issue reported by coccicheck
> ./drivers/irqchip/irq-tango.c:189:1-5: alloc with no test, possible
> model on line 193
>
> Signed-off-by: Hariprasad Kelam <hariprasad.kelam@gmail.com>
> ---
>  drivers/irqchip/irq-tango.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/irqchip/irq-tango.c b/drivers/irqchip/irq-tango.c
> index 34290f0..761b9fa 100644
> --- a/drivers/irqchip/irq-tango.c
> +++ b/drivers/irqchip/irq-tango.c
> @@ -187,6 +187,8 @@ static int __init tangox_irq_init(void __iomem *base, struct resource *baseres,
>  		panic("%pOFn: failed to get address", node);
>
>  	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> +	if (!chip)
> +		return -ENOMEM;
>  	chip->ctl = res.start - baseres->start;
>  	chip->base = base;
>
> -- 

Nothing checks the return value of that function, so bad things will
still happen, only more confusing to debug.  If you really want to
"fix" this, you should either:

- Simply panic() like the other error cases.  If anything here fails,
  the system will not work anyway.

- Replace the panic() calls with error returns and check the return
  value in tangox_of_irq_init().  The system will still end up unusable.

-- 
Måns Rullgård

      reply	other threads:[~2019-07-22  8:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-21 18:15 [PATCH] irqchip/tango: Add NULL check after memory operation Hariprasad Kelam
2019-07-22  8:54 ` Måns Rullgård [this message]

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=yw1xh87efnzd.fsf@mansr.com \
    --to=mans@mansr.com \
    --cc=hariprasad.kelam@gmail.com \
    --cc=jason@lakedaemon.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.w.gonzalez@free.fr \
    --cc=marc.zyngier@arm.com \
    --cc=tglx@linutronix.de \
    /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).