mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Ming Lei <ming.lei@canonical.com>
Cc: linux-kernel@vger.kernel.org,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH] firmware: Don't attempt to allocate zero bytes with vmalloc()
Date: Fri,  5 Oct 2012 18:05:31 +0100	[thread overview]
Message-ID: <1349456731-19977-1-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)

vmalloc() will fail (very loudly) if we try to allocate zero bytes to
read a zero byte file. Instead report that we successfully read in all
zero bytes.

It's not immediately obvious to me that this is better than returning an
error but it seems better to punt the decision about that to the caller
on the off chance that it's sensible.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/base/firmware_class.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 8154145..a14eb92 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -62,6 +62,11 @@ static bool fw_read_file_contents(struct file *file, struct firmware *fw)
 	char *buf;
 
 	size = fw_file_size(file);
+	if (size == 0) {
+		fw->data = NULL;
+		fw->size = 0;
+		return true;
+	}
 	if (size < 0)
 		return false;
 	buf = vmalloc(size);
-- 
1.7.10.4


             reply	other threads:[~2012-10-05 17:05 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-05 17:05 Mark Brown [this message]
2012-10-08 22:56 ` Ming Lei
2012-10-09  4:19   ` Mark Brown
2012-10-09  7:05     ` Ming Lei
2012-10-09  7:13       ` Mark Brown
2012-10-09  7:34         ` Ming Lei
2012-10-09  7:52           ` Mark Brown
2012-10-09 12:02             ` Ming Lei
2012-10-09 12:36               ` Mark Brown
2012-10-09 14:55                 ` Ming Lei
2012-10-10  1:55                   ` Mark Brown

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=1349456731-19977-1-git-send-email-broonie@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@canonical.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

Powered by JetHome