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

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

Reply via email to