Skip to contentSkip to conversation

Coccinelle: introduce list_move.cocci

PATCH Applied Kirill A. Shutemov 10 participants 24 messages Mar 15, 2011 – Mar 22, 2011

Subsystems (15)
lore
Share & tools
lore
#0 lore raw

PATCH 1/13 Coccinelle: introduce list_move.cocci

Use list_move instead of combination of list_del() and list_add()

---
 scripts/coccinelle/api/list/list_move.cocci |   41 +++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 scripts/coccinelle/api/list/list_move.cocci
scripts/coccinelle/api/list/list_move.cocci new file +41 -0
new file mode 100644
index 0000000..2691a8a
@@ -0,0 +1,41 @@
+///
+/// Use list_move() instead of combination of list_del() and list_add()
+///
+// Confidence: High
+// Copyright: (C) 2011 Kirill A. Shutemov. GPLv2.
+// Options: -no_includes -include_headers
+
+virtual context
+virtual patch
+virtual org
+virtual report
+
+@depends on context@
+expression a, b;
+@@
+
+* list_del(a);
+* list_add(a, b);
+
+@depends on patch@
+expression a, b;
+@@
+
+- list_del(a);
+- list_add(a, b);
++ list_move(a, b);
+
+@r depends on report || org@
+expression a, b;
+position p;
+@@
+
+ list_del@p(a);
+ list_add(a, b);
+
+@script:python depends on org || report@
+p << r.p;
+@@
+
+msg = "WARNING: list_move() can be used"
+coccilib.report.print_report(p[0], msg)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 2/13 plat-spear: use list_move() instead of list_del()/list_add() combination

Cc Viresh Kumar <[email protected]>
Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/plat-spear/clock.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
arch/arm/plat-spear/clock.c +1 -3
index ee4f90e..1d24faf 100644
@@ -267,9 +267,7 @@ static void change_parent(struct clk *cclk, struct clk *pclk)
 	unsigned long flags;
 
 	spin_lock_irqsave(&clocks_lock, flags);
-	list_del(&cclk->sibling);
-	list_add(&cclk->sibling, &pclk->children);
-
+	list_move(&cclk->sibling, &pclk->children);
 	cclk->pclk = pclk;
 	spin_unlock_irqrestore(&clocks_lock, flags);
 }
Signature · 1 line
1.7.4.1
Acked-by on v1 2/13
#2 lore raw

Re: [PATCH 02/13] plat-spear: use list_move() instead of list_del()/list_add() combination

Quoted 13 lines · Kirill A. Shutemov
Cc Viresh Kumar <[email protected]>
Cc Russell King <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm/plat-spear/clock.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
arch/arm/plat-spear/clock.c +0 -0
index ee4f90e..1d24faf 100644

arch/arm/plat-spear/clock.c static void change_parent(struct clk *cclk, struct clk *pclk) · line 273

Quoted 10 lines
arch/arm/plat-spear/clock.c +1 -3
@@ -267,9 +267,7 @@ static void change_parent(struct clk *cclk, struct clk *pclk)
 	unsigned long flags;
 
 	spin_lock_irqsave(&clocks_lock, flags);
-	list_del(&cclk->sibling);
-	list_add(&cclk->sibling, &pclk->children);
-
+	list_move(&cclk->sibling, &pclk->children);
 	cclk->pclk = pclk;
 	spin_unlock_irqrestore(&clocks_lock, flags);
 }
Signature · 1 line
viresh
#3 lore raw

PATCH 3/13 dca: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
Cc Maciej Sosnowski <[email protected]>
Cc Andrew Morton <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Dan Carpenter <[email protected]>
---
 drivers/dca/dca-core.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/dca/dca-core.c +2 -4
index c461eda..4abd089 100644
@@ -111,10 +111,8 @@ static void unregister_dca_providers(void)
 	/* at this point only one domain in the list is expected */
 	domain = list_first_entry(&dca_domains, struct dca_domain, node);
 
-	list_for_each_entry_safe(dca, _dca, &domain->dca_providers, node) {
-		list_del(&dca->node);
-		list_add(&dca->node, &unregistered_providers);
-	}
+	list_for_each_entry_safe(dca, _dca, &domain->dca_providers, node)
+		list_move(&dca->node, &unregistered_providers);
 
 	dca_free_domain(domain);
 
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH 4/13 dm: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 drivers/md/dm-log-userspace-base.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/md/dm-log-userspace-base.c +1 -2
index aa2e0c3..1021c89 100644
@@ -394,8 +394,7 @@ static int flush_by_group(struct log_c *lc, struct list_head *flush_list)
 			group[count] = fe->region;
 			count++;
 
-			list_del(&fe->list);
-			list_add(&fe->list, &tmp_list);
+			list_move(&fe->list, &tmp_list);
 
 			type = fe->type;
 			if (count >= MAX_FLUSH_GROUP_COUNT)
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH 5/13 scsi: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 drivers/scsi/esp_scsi.c     |    6 ++----
 drivers/scsi/fcoe/libfcoe.c |    6 ++----
 drivers/scsi/scsi_tgt_lib.c |    6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)
drivers/scsi/esp_scsi.c +2 -4
index 5755852..9a1af1d 100644
@@ -708,8 +708,7 @@ static void esp_maybe_execute_command(struct esp *esp)
 	tp = &esp->target[tgt];
 	lp = dev->hostdata;
 
-	list_del(&ent->list);
-	list_add(&ent->list, &esp->active_cmds);
+	list_move(&ent->list, &esp->active_cmds);
 
 	esp->active_cmd = ent;
 
@@ -1244,8 +1243,7 @@ static int esp_finish_select(struct esp *esp)
 		/* Now that the state is unwound properly, put back onto
 		 * the issue queue.  This command is no longer active.
 		 */
-		list_del(&ent->list);
-		list_add(&ent->list, &esp->queued_cmds);
+		list_move(&ent->list, &esp->queued_cmds);
 		esp->active_cmd = NULL;
 
 		/* Return value ignored by caller, it directly invokes
drivers/scsi/fcoe/libfcoe.c +2 -4
index 625c6be..a1f7025 100644
@@ -1004,10 +1004,8 @@ static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
 	 * the FCF that answers multicast solicitations, not the others that
 	 * are sending periodic multicast advertisements.
 	 */
-	if (mtu_valid) {
-		list_del(&fcf->list);
-		list_add(&fcf->list, &fip->fcfs);
-	}
+	if (mtu_valid)
+		list_move(&fcf->list, &fip->fcfs);
 
 	/*
 	 * If this is the first validated FCF, note the time and
drivers/scsi/scsi_tgt_lib.c +2 -4
index c399be9..4c444b8 100644
@@ -275,10 +275,8 @@ void scsi_tgt_free_queue(struct Scsi_Host *shost)
 
 	for (i = 0; i < ARRAY_SIZE(qdata->cmd_hash); i++) {
 		list_for_each_entry_safe(tcmd, n, &qdata->cmd_hash[i],
-					 hash_list) {
-			list_del(&tcmd->hash_list);
-			list_add(&tcmd->hash_list, &cmds);
-		}
+					 hash_list)
+			list_move(&tcmd->hash_list, &cmds);
 	}
 
 	spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
Signature · 1 line
1.7.4.1
#6 lore raw

Re: [PATCH 05/13] scsi: use list_move() instead of list_del()/list_add() combination

Quoted 8 lines · Kirill A. Shutemov
---
 drivers/scsi/esp_scsi.c     |    6 ++----
 drivers/scsi/fcoe/libfcoe.c |    6 ++----

Hi Kirill,

libfcoe.c doesn't exist anymore in the scsi-misc tree with recent
fcoe transport changes. Specifically, the change you're trying to make should be to fcoe_ctlr.c.

I'll resend an updated patch that applies to scsi-misc and has my
Ack.

Thanks, //Rob

#7 lore raw

PATCH 1/1 scsi: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov

From: Kirill A. Shutemov <[email protected]>

---
 drivers/scsi/esp_scsi.c       |    6 ++----
 drivers/scsi/fcoe/fcoe_ctlr.c |    6 ++----
 drivers/scsi/scsi_tgt_lib.c   |    6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)
drivers/scsi/esp_scsi.c +2 -4
index 5755852..9a1af1d 100644
@@ -708,8 +708,7 @@ static void esp_maybe_execute_command(struct esp *esp)
 	tp = &esp->target[tgt];
 	lp = dev->hostdata;
 
-	list_del(&ent->list);
-	list_add(&ent->list, &esp->active_cmds);
+	list_move(&ent->list, &esp->active_cmds);
 
 	esp->active_cmd = ent;
 
@@ -1244,8 +1243,7 @@ static int esp_finish_select(struct esp *esp)
 		/* Now that the state is unwound properly, put back onto
 		 * the issue queue.  This command is no longer active.
 		 */
-		list_del(&ent->list);
-		list_add(&ent->list, &esp->queued_cmds);
+		list_move(&ent->list, &esp->queued_cmds);
 		esp->active_cmd = NULL;
 
 		/* Return value ignored by caller, it directly invokes
drivers/scsi/fcoe/fcoe_ctlr.c +2 -4
index c93f007..fb3a506 100644
@@ -978,10 +978,8 @@ static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
 	 * the FCF that answers multicast solicitations, not the others that
 	 * are sending periodic multicast advertisements.
 	 */
-	if (mtu_valid) {
-		list_del(&fcf->list);
-		list_add(&fcf->list, &fip->fcfs);
-	}
+	if (mtu_valid)
+		list_move(&fcf->list, &fip->fcfs);
 
 	/*
 	 * If this is the first validated FCF, note the time and
drivers/scsi/scsi_tgt_lib.c +2 -4
index c399be9..4c444b8 100644
@@ -275,10 +275,8 @@ void scsi_tgt_free_queue(struct Scsi_Host *shost)
 
 	for (i = 0; i < ARRAY_SIZE(qdata->cmd_hash); i++) {
 		list_for_each_entry_safe(tcmd, n, &qdata->cmd_hash[i],
-					 hash_list) {
-			list_del(&tcmd->hash_list);
-			list_add(&tcmd->hash_list, &cmds);
-		}
+					 hash_list)
+			list_move(&tcmd->hash_list, &cmds);
 	}
 
 	spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
#8 lore raw

Re: [PATCH] scsi: use list_move() instead of list_del()/list_add() combination

Quoted 7 lines · Robert Love

From: Kirill A. Shutemov <[email protected]>

You can junk the cc's; they're mostly annotations for git-send-email

Quoted 1 line

And this has to be Signed-off-by not Acked-by. The reason is that you've resent the patch (and altered it as you transmitted it) so that makes you part of the signoff chain. If you ack a patch, it means I can pick it up from source and you as maintainer didn't actually touch it.

James

#9 lore raw

Re: [PATCH] scsi: use list_move() instead of list_del()/list_add() combination

Quoted 9 lines · James Bottomley
Quoted 7 lines · Robert Love

From: Kirill A. Shutemov <[email protected]>

Quoted 9 lines

You can junk the cc's; they're mostly annotations for git-send-email

Quoted 1 line

And this has to be Signed-off-by not Acked-by. The reason is that you've resent the patch (and altered it as you transmitted it) so that makes you part of the signoff chain. If you ack a patch, it means I can pick it up from source and you as maintainer didn't actually touch it.

Thanks for the clarification James.

Let me know if you, or anyone else, wants me to resend the patch with the Signed-off line.

//Rob

#10 lore raw

PATCH 6/13 omap: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 drivers/video/omap/blizzard.c |    3 +--
 drivers/video/omap/hwa742.c   |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/video/omap/blizzard.c +1 -2
index 87785c2..c0504a8 100644
@@ -397,8 +397,7 @@ static inline void free_req(struct blizzard_request *req)
 
 	spin_lock_irqsave(&blizzard.req_lock, flags);
 
-	list_del(&req->entry);
-	list_add(&req->entry, &blizzard.free_req_list);
+	list_move(&req->entry, &blizzard.free_req_list);
 	if (!(req->flags & REQ_FROM_IRQ_POOL))
 		up(&blizzard.req_sema);
 
drivers/video/omap/hwa742.c +1 -2
index 0016f77..084aa0a 100644
@@ -269,8 +269,7 @@ static inline void free_req(struct hwa742_request *req)
 
 	spin_lock_irqsave(&hwa742.req_lock, flags);
 
-	list_del(&req->entry);
-	list_add(&req->entry, &hwa742.free_req_list);
+	list_move(&req->entry, &hwa742.free_req_list);
 	if (!(req->flags & REQ_FROM_IRQ_POOL))
 		up(&hwa742.req_sema);
 
Signature · 1 line
1.7.4.1
Acked-by on v1 6/13
#11 lore raw

Re: [PATCH 06/13] omap: use list_move() instead of list_del()/list_add() combination

Quoted 8 lines · Kirill A. Shutemov
---
 drivers/video/omap/blizzard.c |    3 +--
 drivers/video/omap/hwa742.c   |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

Tomi

#12 lore raw

PATCH 7/13 vmlfb: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 drivers/video/vermilion/vermilion.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/video/vermilion/vermilion.c +1 -2
index 931a567..970e43d 100644
@@ -891,8 +891,7 @@ static int vmlfb_set_par(struct fb_info *info)
 	int ret;
 
 	mutex_lock(&vml_mutex);
-	list_del(&vinfo->head);
-	list_add(&vinfo->head, (subsys) ? &global_has_mode : &global_no_mode);
+	list_move(&vinfo->head, (subsys) ? &global_has_mode : &global_no_mode);
 	ret = vmlfb_set_par_locked(vinfo);
 
 	mutex_unlock(&vml_mutex);
Signature · 1 line
1.7.4.1
#13 lore raw

Re: [PATCH 06/13] omap: use list_move() instead of list_del()/list_add() combination

Quoted 11 lines · Tomi Valkeinen
Quoted 8 lines · Kirill A. Shutemov
---
 drivers/video/omap/blizzard.c |    3 +--
 drivers/video/omap/hwa742.c   |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
Quoted 7 lines · Kirill A. Shutemov
---
 drivers/video/vermilion/vermilion.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

Both applied, thanks.

#14 lore raw

PATCH 8/13 JFS: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 fs/jfs/jfs_txnmgr.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
fs/jfs/jfs_txnmgr.c +3 -6
index 9466957..8cb7b92 100644
@@ -2979,12 +2979,9 @@ int jfs_sync(void *arg)
 				 * put back on the anon_list.
 				 */
 
-				/* Take off anon_list */
-				list_del(&jfs_ip->anon_inode_list);
-
-				/* Put on anon_list2 */
-				list_add(&jfs_ip->anon_inode_list,
-					 &TxAnchor.anon_list2);
+				/* Move anon_list -> anon_list2 */
+				list_move(&jfs_ip->anon_inode_list,
+					  &TxAnchor.anon_list2);
 
 				TXN_UNLOCK();
 				iput(ip);
Signature · 1 line
1.7.4.1
Acked-by on v1 8/13
#15 lore raw

Re: [PATCH 08/13] JFS: use list_move() instead of list_del()/list_add() combination

Quoted 1 line · Kirill A. Shutemov
Quoted 28 lines

---
 fs/jfs/jfs_txnmgr.c |    9 +++------

 1 files changed, 3 insertions(+), 6 deletions(-)
fs/jfs/jfs_txnmgr.c +3 -7
index 9466957..8cb7b92 100644
@@ -2979,12 +2979,9 @@ int jfs_sync(void *arg)
                                 * put back on the anon_list.
                                 */
 
-                               /* Take off anon_list */
-                               list_del(&jfs_ip->anon_inode_list);
-
-                               /* Put on anon_list2 */
-                               list_add(&jfs_ip->anon_inode_list,
-                                        &TxAnchor.anon_list2);
+                               /* Move anon_list -> anon_list2 */
+                               list_move(&jfs_ip->anon_inode_list,
+                                         &TxAnchor.anon_list2);
 
                                TXN_UNLOCK();
                                iput(ip);
--

1.7.4.1

#16 lore raw

PATCH 9/13 audit: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 kernel/audit_tree.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)
kernel/audit_tree.c +5 -10
index 37b2bea..6fe56d2 100644
@@ -591,8 +591,7 @@ void audit_trim_trees(void)
 
 		tree = container_of(cursor.next, struct audit_tree, list);
 		get_tree(tree);
-		list_del(&cursor);
-		list_add(&cursor, &tree->list);
+		list_move(&cursor, &tree->list);
 		mutex_unlock(&audit_filter_mutex);
 
 		err = kern_path(tree->pathname, 0, &path);
@@ -744,8 +743,7 @@ int audit_tag_tree(char *old, char *new)
 
 		tree = container_of(cursor.next, struct audit_tree, list);
 		get_tree(tree);
-		list_del(&cursor);
-		list_add(&cursor, &tree->list);
+		list_move(&cursor, &tree->list);
 		mutex_unlock(&audit_filter_mutex);
 
 		err = kern_path(tree->pathname, 0, &path2);
@@ -769,10 +767,8 @@ int audit_tag_tree(char *old, char *new)
 
 		mutex_lock(&audit_filter_mutex);
 		spin_lock(&hash_lock);
-		if (!tree->goner) {
-			list_del(&tree->list);
-			list_add(&tree->list, &tree_list);
-		}
+		if (!tree->goner)
+			list_move(&tree->list, &tree_list);
 		spin_unlock(&hash_lock);
 		put_tree(tree);
 	}
@@ -782,8 +778,7 @@ int audit_tag_tree(char *old, char *new)
 
 		tree = container_of(barrier.prev, struct audit_tree, list);
 		get_tree(tree);
-		list_del(&tree->list);
-		list_add(&tree->list, &barrier);
+		list_move(&tree->list, &barrier);
 		mutex_unlock(&audit_filter_mutex);
 
 		if (!failed) {
Signature · 1 line
1.7.4.1
#17 lore raw

PATCH 10/13 clockevent: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 kernel/time/clockevents.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
kernel/time/clockevents.c +2 -4
index d7395fd..b1fa45d 100644
@@ -168,8 +168,7 @@ static void clockevents_notify_released(void)
 	while (!list_empty(&clockevents_released)) {
 		dev = list_entry(clockevents_released.next,
 				 struct clock_event_device, list);
-		list_del(&dev->list);
-		list_add(&dev->list, &clockevent_devices);
+		list_move(&dev->list, &clockevent_devices);
 		clockevents_do_notify(CLOCK_EVT_NOTIFY_ADD, dev);
 	}
 }
@@ -221,8 +220,7 @@ void clockevents_exchange_device(struct clock_event_device *old,
 	 */
 	if (old) {
 		clockevents_set_mode(old, CLOCK_EVT_MODE_UNUSED);
-		list_del(&old->list);
-		list_add(&old->list, &clockevents_released);
+		list_move(&old->list, &clockevents_released);
 	}
 
 	if (new) {
Signature · 1 line
1.7.4.1
#18 lore raw

PATCH 11/13 mm: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc KAMEZAWA Hiroyuki <[email protected]>
---
 mm/page_alloc.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
mm/page_alloc.c +2 -3
index cdef1d4..55fa2ae 100644
@@ -863,9 +863,8 @@ static int move_freepages(struct zone *zone,
 		}
 
 		order = page_order(page);
-		list_del(&page->lru);
-		list_add(&page->lru,
-			&zone->free_area[order].free_list[migratetype]);
+		list_move(&page->lru,
+			  &zone->free_area[order].free_list[migratetype]);
 		page += 1 << order;
 		pages_moved += 1 << order;
 	}
Signature · 8 lines
1.7.4.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 11/13
#19 lore raw

Re: [PATCH 11/13] mm: use list_move() instead of list_del()/list_add() combination

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#20 lore raw

PATCH 12/13 alsa: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
---
 sound/pci/ctxfi/ctvmem.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
sound/pci/ctxfi/ctvmem.c +1 -2
index 65da6e4..b78f3fc 100644
@@ -52,8 +52,7 @@ get_vm_block(struct ct_vm *vm, unsigned int size)
 
 	if (entry->size == size) {
 		/* Move the vm node from unused list to used list directly */
-		list_del(&entry->list);
-		list_add(&entry->list, &vm->used);
+		list_move(&entry->list, &vm->used);
 		vm->size -= size;
 		block = entry;
 		goto out;
Signature · 1 line
1.7.4.1
Applied
#21 lore raw

Re: [PATCH 12/13] alsa: use list_move() instead of list_del()/list_add() combination

At Wed, 16 Mar 2011 00:53:24 +0200,

Quoted 5 lines · Kirill A. Shutemov

Thanks, applied now.

Takashi

Quoted 21 lines
---
 sound/pci/ctxfi/ctvmem.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
sound/pci/ctxfi/ctvmem.c +1 -2
index 65da6e4..b78f3fc 100644
@@ -52,8 +52,7 @@ get_vm_block(struct ct_vm *vm, unsigned int size)
 
 	if (entry->size == size) {
 		/* Move the vm node from unused list to used list directly */
-		list_del(&entry->list);
-		list_add(&entry->list, &vm->used);
+		list_move(&entry->list, &vm->used);
 		vm->size -= size;
 		block = entry;
 		goto out;
Signature · 1 line
1.7.4.1
#22 lore raw

PATCH 13/13 perf: use list_move() instead of list_del()/list_add() combination

In reply to Kirill A. Shutemov
Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/session.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
tools/perf/util/session.c +1 -2
index 105f00b..8b8e04e 100644
@@ -499,8 +499,7 @@ static void flush_sample_queue(struct perf_session *s,
 					   iter->file_offset);
 
 		os->last_flush = iter->timestamp;
-		list_del(&iter->list);
-		list_add(&iter->list, &os->sample_cache);
+		list_move(&iter->list, &os->sample_cache);
 	}
 
 	if (list_empty(head)) {
Signature · 1 line
1.7.4.1
#23 lore raw
In reply to Kirill A. Shutemov

Kirill,

Thank you very much for your contribution. Nevertheless, there is a small problem. In the very last python rule, you use org || report, but actually you are not generating org mode.

To make an org mode rule, you should replace the call to

coccilib.report.print_report

by a call to

coccilib.org.print_todo

thanks,
julia

Quoted 63 lines · Kirill A. Shutemov

Use list_move instead of combination of list_del() and list_add()

---
 scripts/coccinelle/api/list/list_move.cocci |   41 +++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 scripts/coccinelle/api/list/list_move.cocci
scripts/coccinelle/api/list/list_move.cocci new file +41 -0
new file mode 100644
index 0000000..2691a8a
@@ -0,0 +1,41 @@
+///
+/// Use list_move() instead of combination of list_del() and list_add()
+///
+// Confidence: High
+// Copyright: (C) 2011 Kirill A. Shutemov. GPLv2.
+// Options: -no_includes -include_headers
+
+virtual context
+virtual patch
+virtual org
+virtual report
+
+@depends on context@
+expression a, b;
+@@
+
+* list_del(a);
+* list_add(a, b);
+
+@depends on patch@
+expression a, b;
+@@
+
+- list_del(a);
+- list_add(a, b);
++ list_move(a, b);
+
+@r depends on report || org@
+expression a, b;
+position p;
+@@
+
+ list_del@p(a);
+ list_add(a, b);
+
+@script:python depends on org || report@
+p << r.p;
+@@
+
+msg = "WARNING: list_move() can be used"
+coccilib.report.print_report(p[0], msg)
Signature · 1 line
1.7.4.1