From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jeff Moyer <jmoyer@redhat.com>
Cc: Julia Lawall <Julia.Lawall@lip6.fr>,
Joshua Morris <josh.h.morris@us.ibm.com>,
kernel-janitors@vger.kernel.org,
Philip Kelleher <pjk1939@linux.vnet.ibm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] block: fix error return code
Date: Fri, 8 Aug 2014 12:21:52 +0300 [thread overview]
Message-ID: <20140808092152.GJ4856@mwanda> (raw)
In-Reply-To: <x49sil89djr.fsf@segfault.boston.devel.redhat.com>
On Thu, Aug 07, 2014 at 05:48:24PM -0400, Jeff Moyer wrote:
> BTW, just above this there is questionable code:
>
> st = rsxx_get_num_targets(card, &card->n_targets);
> if (st)
> dev_info(CARD_TO_DEV(card),
> "Failed reading the number of DMA targets\n");
>
> card->ctrl = kzalloc(card->n_targets * sizeof(*card->ctrl), GFP_KERNEL);
> if (!card->ctrl) {
> st = -ENOMEM;
> goto failed_dma_setup;
> }
>
> >From my reading of the kzalloc code, ZERO_SIZE_PTR (which is 16 cast to
> a void *) would be returned from that kzalloc call if the
> rsxx_get_num_targets call failed (since you'd be kzalloc-ing 0 bytes).
> That would lead to the !card->ctrl check not working, right?
>
ZERO_SIZE_PTR is a subtle thing. The if (!card->ctrl) check correctly
tells you if you allocated enough space to hold zero elements. Which is
yes so we can continue without a problem.
Of course, you'd have to look at the surrounding code to see if there is
a problem... I think I have seen dereferencing ZERO_SIZE_PTR bugs in
the past, but they are rare.
> I'd suggest not continuing after rsxx_get_num_targets fails.
Introducing new failures is a bad thing unless you know the code very
well or you can test it. Your instinct should always be to not do that.
regards,
dan carpenter
next prev parent reply other threads:[~2014-08-08 9:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-07 20:57 [PATCH 0/4] fix error return code Julia Lawall
2014-08-07 20:57 ` [PATCH 2/4] gdrom: " Julia Lawall
2014-08-07 21:41 ` Jeff Moyer
2014-08-07 20:57 ` [PATCH 1/4] umem: " Julia Lawall
2014-08-07 21:41 ` Jeff Moyer
2014-08-07 20:57 ` [PATCH 3/4] block: " Julia Lawall
2014-08-07 21:48 ` Jeff Moyer
2014-08-08 4:58 ` Julia Lawall
2014-08-08 9:21 ` Dan Carpenter [this message]
2014-08-07 20:57 ` [PATCH 4/4] usb: gadget: " Julia Lawall
2014-08-07 21:50 ` Jeff Moyer
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=20140808092152.GJ4856@mwanda \
--to=dan.carpenter@oracle.com \
--cc=Julia.Lawall@lip6.fr \
--cc=jmoyer@redhat.com \
--cc=josh.h.morris@us.ibm.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pjk1939@linux.vnet.ibm.com \
/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