sh: Replace an explicit computation by the use of the container_of macro
authorNicolas Palix <npalix@diku.dk>
Mon, 7 Dec 2009 09:38:55 +0000 (10:38 +0100)
committerPaul Mundt <lethal@linux-sh.org>
Wed, 9 Dec 2009 03:36:51 +0000 (12:36 +0900)
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>

Signed-off-by: Nicolas Palix <npalix@diku.dk>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/kernel/cpu/irq/ipr.c

index c1508a90fc6af2049946e31de8c98a764b009863..9282d965a1b66082ef78f9c77e35150ac9778b47 100644 (file)
  * 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)