Skip to contentSkip to conversation

arch/sh: Replace an explicit computation by the use of the container_of macro

PATCH Applied Nicolas Palix 2 participants 2 messages Dec 7, 2009 – Dec 9, 2009

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

PATCH 1/1 arch/sh: Replace an explicit computation by the use of the container_of macro

From 945e75c0e3202ab4cd0b8f185ea4be5609806edb Mon Sep 17 00:00:00 2001
From: Nicolas Palix <[email protected]>
Date: Mon, 7 Dec 2009 10:38:55 +0100

The macro container_of from kernel.h performs the same pointer arithmetic operation.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
type T;
expression mptr;
expression member;
@@

- (void *)((char *)mptr - offsetof(T, member))
+ container_of(mptr, T, member)
// </smpl>

---
 arch/sh/kernel/cpu/irq/ipr.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/sh/kernel/cpu/irq/ipr.c +4 -3
index c1508a9..9282d96 100644
@@ -17,16 +17,17 @@
  * for more details.
  */
 #include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
 #include <linux/irq.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/io.h>
-#include <linux/interrupt.h>
 #include <linux/topology.h>
 
 static inline struct ipr_desc *get_ipr_desc(unsigned int irq)
 {
 	struct irq_chip *chip = get_irq_chip(irq);
-	return (void *)((char *)chip - offsetof(struct ipr_desc, chip));
+	return container_of(chip, struct ipr_desc, chip);
 }
 
 static void disable_ipr_irq(unsigned int irq)
Signature · 1 line
1.6.0.4
Applied
#1 lore raw
Quoted 17 lines · Nicolas Palix

From 945e75c0e3202ab4cd0b8f185ea4be5609806edb Mon Sep 17 00:00:00 2001
From: Nicolas Palix <[email protected]>
Date: Mon, 7 Dec 2009 10:38:55 +0100

The macro container_of from kernel.h performs the same pointer arithmetic operation.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
type T;
expression mptr;
expression member;
@@

Quoted 5 lines

- (void *)((char *)mptr - offsetof(T, member))
+ container_of(mptr, T, member)
// </smpl>

Applied, thanks.