From patchwork Tue Dec 8 14:25:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 7798071 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BB73DBEEE1 for ; Tue, 8 Dec 2015 14:26:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 90187204DE for ; Tue, 8 Dec 2015 14:26:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 693F9203DB for ; Tue, 8 Dec 2015 14:26:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755241AbbLHO0c (ORCPT ); Tue, 8 Dec 2015 09:26:32 -0500 Received: from m50-134.163.com ([123.125.50.134]:44517 "EHLO m50-134.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932537AbbLHO0b (ORCPT ); Tue, 8 Dec 2015 09:26:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=yV4MA+13o0Q3s4qXR+ G6FRGWjmnjUbdhr7BzQP5Lkes=; b=p+D+Hi8e4HUoyUkcPC1JFRvZAlTKkxICB3 5rit6kZ6GD2+c62xEyqdsJz0kPTD5bD271zACQucEcv46DMviuTOmlxCynBF2b1U UxDLJvMplXwT9fth3u3Tf9VxewmSsTL+dRoJDaYApa/YDUuV/jvL7Smxgo4ocUwa k/KIUNM4Y= Received: from localhost (unknown [116.77.139.106]) by smtp4 (Coremail) with SMTP id DtGowEDpnEFp6GZWhmUIAA--.5815S3; Tue, 08 Dec 2015 22:25:46 +0800 (CST) From: Geliang Tang To: "Richard Russon (FlatCap)" , Jens Axboe Cc: Geliang Tang , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] LDM: use list_for_each_entry* Date: Tue, 8 Dec 2015 22:25:41 +0800 Message-Id: X-Mailer: git-send-email 2.5.0 X-CM-TRANSID: DtGowEDpnEFp6GZWhmUIAA--.5815S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxtF1fCFW3KrykXw1rZFyrWFg_yoW3CF15pF s5GFW2qr4xArs5ur45Xr409r4ayw1kJr1jka4rCwsavr1jkrsaqF1akas0yr1YyrWDury5 Wr4qkF1Y9w4kCrUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UyWlkUUUUU= X-Originating-IP: [116.77.139.106] X-CM-SenderInfo: 5jhoxtpqjwt0rj6rljoofrz/xtbBygvKmVO+gZsSpQAAsS Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use list_for_each_entry*() instead of list_for_each*() to simplify the code. Fix coding style by the way. Signed-off-by: Geliang Tang --- block/partitions/ldm.c | 108 ++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 59 deletions(-) diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c index e507cfb..3b86705 100644 --- a/block/partitions/ldm.c +++ b/block/partitions/ldm.c @@ -601,15 +601,14 @@ out: * Return: Pointer, A matching vblk was found * NULL, No match, or an error */ -static struct vblk * ldm_get_disk_objid (const struct ldmdb *ldb) +static struct vblk *ldm_get_disk_objid(const struct ldmdb *ldb) { - struct list_head *item; + struct vblk *v; - BUG_ON (!ldb); + BUG_ON(!ldb); - list_for_each (item, &ldb->v_disk) { - struct vblk *v = list_entry (item, struct vblk, list); - if (!memcmp (v->vblk.disk.disk_id, ldb->ph.disk_id, GUID_SIZE)) + list_for_each_entry(v, &ldb->v_disk, list) { + if (!memcmp(v->vblk.disk.disk_id, ldb->ph.disk_id, GUID_SIZE)) return v; } @@ -633,34 +632,32 @@ static struct vblk * ldm_get_disk_objid (const struct ldmdb *ldb) * Return: 'true' Partition created * 'false' Error, probably a range checking problem */ -static bool ldm_create_data_partitions (struct parsed_partitions *pp, - const struct ldmdb *ldb) +static bool ldm_create_data_partitions(struct parsed_partitions *pp, + const struct ldmdb *ldb) { - struct list_head *item; struct vblk *vb; struct vblk *disk; struct vblk_part *part; int part_num = 1; - BUG_ON (!pp || !ldb); + BUG_ON(!pp || !ldb); - disk = ldm_get_disk_objid (ldb); + disk = ldm_get_disk_objid(ldb); if (!disk) { - ldm_crit ("Can't find the ID of this disk in the database."); + ldm_crit("Can't find the ID of this disk in the database."); return false; } strlcat(pp->pp_buf, " [LDM]", PAGE_SIZE); /* Create the data partitions */ - list_for_each (item, &ldb->v_part) { - vb = list_entry (item, struct vblk, list); + list_for_each_entry(vb, &ldb->v_part, list) { part = &vb->vblk.part; if (part->disk_id != disk->obj_id) continue; - put_partition (pp, part_num, ldb->ph.logical_disk_start + + put_partition(pp, part_num, ldb->ph.logical_disk_start + part->start, part->size); part_num++; } @@ -1231,20 +1228,19 @@ static bool ldm_parse_vblk (const u8 *buf, int len, struct vblk *vb) * Return: 'true' The VBLK was added * 'false' An error occurred */ -static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb) +static bool ldm_ldmdb_add(u8 *data, int len, struct ldmdb *ldb) { - struct vblk *vb; - struct list_head *item; + struct vblk *vb, *v; - BUG_ON (!data || !ldb); + BUG_ON(!data || !ldb); - vb = kmalloc (sizeof (*vb), GFP_KERNEL); + vb = kmalloc(sizeof(*vb), GFP_KERNEL); if (!vb) { - ldm_crit ("Out of memory."); + ldm_crit("Out of memory."); return false; } - if (!ldm_parse_vblk (data, len, vb)) { + if (!ldm_parse_vblk(data, len, vb)) { kfree(vb); return false; /* Already logged */ } @@ -1253,29 +1249,28 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb) switch (vb->type) { case VBLK_DGR3: case VBLK_DGR4: - list_add (&vb->list, &ldb->v_dgrp); + list_add(&vb->list, &ldb->v_dgrp); break; case VBLK_DSK3: case VBLK_DSK4: - list_add (&vb->list, &ldb->v_disk); + list_add(&vb->list, &ldb->v_disk); break; case VBLK_VOL5: - list_add (&vb->list, &ldb->v_volu); + list_add(&vb->list, &ldb->v_volu); break; case VBLK_CMP3: - list_add (&vb->list, &ldb->v_comp); + list_add(&vb->list, &ldb->v_comp); break; case VBLK_PRT3: /* Sort by the partition's start sector. */ - list_for_each (item, &ldb->v_part) { - struct vblk *v = list_entry (item, struct vblk, list); + list_for_each_entry(v, &ldb->v_part, list) { if ((v->vblk.part.disk_id == vb->vblk.part.disk_id) && (v->vblk.part.start > vb->vblk.part.start)) { - list_add_tail (&vb->list, &v->list); + list_add_tail(&vb->list, &v->list); return true; } } - list_add_tail (&vb->list, &ldb->v_part); + list_add_tail(&vb->list, &ldb->v_part); break; } return true; @@ -1293,13 +1288,12 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb) * Return: 'true' Success, the VBLK was added to the list * 'false' Error, a problem occurred */ -static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) +static bool ldm_frag_add(const u8 *data, int size, struct list_head *frags) { struct frag *f; - struct list_head *item; int rec, num, group; - BUG_ON (!data || !frags); + BUG_ON(!data || !frags); if (size < 2 * VBLK_SIZE_HEAD) { ldm_error("Value of size is to small."); @@ -1310,7 +1304,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) rec = get_unaligned_be16(data + 0x0C); num = get_unaligned_be16(data + 0x0E); if ((num < 1) || (num > 4)) { - ldm_error ("A VBLK claims to have %d parts.", num); + ldm_error("A VBLK claims to have %d parts.", num); return false; } if (rec >= num) { @@ -1318,15 +1312,14 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) return false; } - list_for_each (item, frags) { - f = list_entry (item, struct frag, list); + list_for_each_entry(f, frags, list) { if (f->group == group) goto found; } - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL); + f = kmalloc(sizeof(*f) + size*num, GFP_KERNEL); if (!f) { - ldm_crit ("Out of memory."); + ldm_crit("Out of memory."); return false; } @@ -1335,14 +1328,14 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) f->rec = rec; f->map = 0xFF << num; - list_add_tail (&f->list, frags); + list_add_tail(&f->list, frags); found: if (rec >= f->num) { ldm_error("REC value (%d) exceeds NUM value (%d)", rec, f->num); return false; } if (f->map & (1 << rec)) { - ldm_error ("Duplicate VBLK, part %d.", rec); + ldm_error("Duplicate VBLK, part %d.", rec); f->map &= 0x7F; /* Mark the group as broken */ return false; } @@ -1357,20 +1350,20 @@ found: /** * ldm_frag_free - Free a linked list of VBLK fragments - * @list: Linked list of fragments + * @lh: Linked list of fragments * * Free a linked list of VBLK fragments * * Return: none */ -static void ldm_frag_free (struct list_head *list) +static void ldm_frag_free(struct list_head *lh) { - struct list_head *item, *tmp; + struct frag *f, *tmp; - BUG_ON (!list); + BUG_ON(!lh); - list_for_each_safe (item, tmp, list) - kfree (list_entry (item, struct frag, list)); + list_for_each_entry_safe(f, tmp, lh, list) + kfree(f); } /** @@ -1384,23 +1377,20 @@ static void ldm_frag_free (struct list_head *list) * Return: 'true' All the fragments we added successfully * 'false' One or more of the fragments we invalid */ -static bool ldm_frag_commit (struct list_head *frags, struct ldmdb *ldb) +static bool ldm_frag_commit(struct list_head *frags, struct ldmdb *ldb) { struct frag *f; - struct list_head *item; - - BUG_ON (!frags || !ldb); - list_for_each (item, frags) { - f = list_entry (item, struct frag, list); + BUG_ON(!frags || !ldb); + list_for_each_entry(f, frags, list) { if (f->map != 0xFF) { - ldm_error ("VBLK group %d is incomplete (0x%02x).", + ldm_error("VBLK group %d is incomplete (0x%02x).", f->group, f->map); return false; } - if (!ldm_ldmdb_add (f->data, f->num*ldb->vm.vblk_size, ldb)) + if (!ldm_ldmdb_add(f->data, f->num*ldb->vm.vblk_size, ldb)) return false; /* Already logged */ } return true; @@ -1478,14 +1468,14 @@ out: * * Return: none */ -static void ldm_free_vblks (struct list_head *lh) +static void ldm_free_vblks(struct list_head *lh) { - struct list_head *item, *tmp; + struct vblk *v, *tmp; - BUG_ON (!lh); + BUG_ON(!lh); - list_for_each_safe (item, tmp, lh) - kfree (list_entry (item, struct vblk, list)); + list_for_each_entry_safe(v, tmp, lh, list) + kfree(v); }