lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1426295577-10836-3-git-send-email-akinobu.mita@gmail.com>
Date:	Sat, 14 Mar 2015 10:12:55 +0900
From:	Akinobu Mita <akinobu.mita@...il.com>
To:	linux-kernel@...r.kernel.org
Cc:	Akinobu Mita <akinobu.mita@...il.com>,
	Jiri Kosina <jkosina@...e.cz>
Subject: [PATCH] pktcdvd: convert char array to bitmap

The written[] array in pkt_gather_data() can be converted to bitmap.
It can reduce stack usage and simplify the code a bit.

Signed-off-by: Akinobu Mita <akinobu.mita@...il.com>
Cc: Jiri Kosina <jkosina@...e.cz>
---
 drivers/block/pktcdvd.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 09e628da..1aff5ca 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -1019,7 +1019,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
 	int frames_read = 0;
 	struct bio *bio;
 	int f;
-	char written[PACKET_MAX_SIZE];
+	DECLARE_BITMAP(written, PACKET_MAX_SIZE);
 
 	BUG_ON(bio_list_empty(&pkt->orig_bios));
 
@@ -1029,7 +1029,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
 	/*
 	 * Figure out which frames we need to read before we can write.
 	 */
-	memset(written, 0, sizeof(written));
+	bitmap_zero(written, PACKET_MAX_SIZE);
 	spin_lock(&pkt->lock);
 	bio_list_for_each(bio, &pkt->orig_bios) {
 		int first_frame = (bio->bi_iter.bi_sector - pkt->sector) /
@@ -1038,8 +1038,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
 		pd->stats.secs_w += num_frames * (CD_FRAMESIZE >> 9);
 		BUG_ON(first_frame < 0);
 		BUG_ON(first_frame + num_frames > pkt->frames);
-		for (f = first_frame; f < first_frame + num_frames; f++)
-			written[f] = 1;
+		bitmap_set(written, first_frame, num_frames);
 	}
 	spin_unlock(&pkt->lock);
 
@@ -1052,12 +1051,9 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt)
 	/*
 	 * Schedule reads for missing parts of the packet.
 	 */
-	for (f = 0; f < pkt->frames; f++) {
+	for_each_clear_bit(f, written, pkt->frames) {
 		int p, offset;
 
-		if (written[f])
-			continue;
-
 		bio = pkt->r_bios[f];
 		bio_reset(bio);
 		bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ