From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755786AbbCNBN3 (ORCPT ); Fri, 13 Mar 2015 21:13:29 -0400 Received: from mail-pd0-f182.google.com ([209.85.192.182]:35660 "EHLO mail-pd0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755516AbbCNBNZ (ORCPT ); Fri, 13 Mar 2015 21:13:25 -0400 From: Akinobu Mita To: linux-kernel@vger.kernel.org Cc: Akinobu Mita , Jiri Kosina Subject: [PATCH] pktcdvd: convert char array to bitmap Date: Sat, 14 Mar 2015 10:12:55 +0900 Message-Id: <1426295577-10836-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com> References: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Jiri Kosina --- 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