mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Art Haas" <ahaas@airmail.net>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Remove variable-sized stack in drivers/char/fbmem.c
Date: Tue, 13 Apr 2004 17:33:02 -0500	[thread overview]
Message-ID: <20040413223302.GF23640@artsapartment.org> (raw)

Hi.

The following patch replaces the variably sized stack with a kmalloc()
invocation. A brief search around the code suggests that memory
allocation as this function was doing is unusual.

Art Haas

===== drivers/video/fbmem.c 1.96 vs edited =====
--- 1.96/drivers/video/fbmem.c	Mon Apr 12 12:55:32 2004
+++ edited/drivers/video/fbmem.c	Tue Apr 13 16:53:38 2004
@@ -980,21 +980,29 @@
 int
 fb_blank(struct fb_info *info, int blank)
 {	
-	/* ??? Variable sized stack allocation.  */
-	u16 black[info->cmap.len];
+	int res;
+	size_t size;
+	u16 * black = NULL;
 	struct fb_cmap cmap;
 	
 	if (info->fbops->fb_blank && !info->fbops->fb_blank(blank, info))
 		return 0;
 	if (blank) { 
-		memset(black, 0, info->cmap.len * sizeof(u16));
+		size = info->cmap.len * sizeof(*black);
+		black = kmalloc(size, GFP_KERNEL);
+		if (!black)
+			return -ENOMEM;
+		memset(black, 0, size);
 		cmap.red = cmap.green = cmap.blue = black;
 		cmap.transp = info->cmap.transp ? black : NULL;
 		cmap.start = info->cmap.start;
 		cmap.len = info->cmap.len;
 	} else
 		cmap = info->cmap;
-	return fb_set_cmap(&cmap, 1, info);
+	res = fb_set_cmap(&cmap, 1, info);
+	if (black)
+		kfree(black);
+	return res;
 }
 
 static int 
-- 
Man once surrendering his reason, has no remaining guard against absurdities
the most monstrous, and like a ship without rudder, is the sport of every wind.

-Thomas Jefferson to James Smith, 1822

                 reply	other threads:[~2004-04-13 23:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20040413223302.GF23640@artsapartment.org \
    --to=ahaas@airmail.net \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®