public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>, Jiri Kosina <jkosina@suse.cz>
Subject: [PATCH] pktcdvd: convert char array to bitmap
Date: Sat, 14 Mar 2015 10:12:55 +0900	[thread overview]
Message-ID: <1426295577-10836-3-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com>

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@gmail.com>
Cc: Jiri Kosina <jkosina@suse.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


  parent reply	other threads:[~2015-03-14  1:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-14  1:12 [PATCH] hpsa: cleanup bitops usage Akinobu Mita
2015-03-14  1:12 ` [PATCH] cpqarray: simplify bitops usages Akinobu Mita
2015-03-14  1:12 ` Akinobu Mita [this message]
2015-03-14  1:12 ` [PATCH] drbd: use bitmap_weight() Akinobu Mita
2015-03-20 15:14   ` [Drbd-dev] " Lars Ellenberg
2015-03-22  2:11     ` Akinobu Mita
2015-03-14  1:12 ` [PATCH] ia64: Use bitmap_weight Akinobu Mita

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=1426295577-10836-3-git-send-email-akinobu.mita@gmail.com \
    --to=akinobu.mita@gmail.com \
    --cc=jkosina@suse.cz \
    --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