linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arch/sh: Replace an explicit computation by the use of the container_of macro
@ 2009-12-07  9:46 Nicolas Palix
  2009-12-09  3:44 ` Paul Mundt
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Palix @ 2009-12-07  9:46 UTC (permalink / raw)
  To: Paul Mundt, kernel-janitors, Stuart Menefy, linux-sh, linux-kernel

>From 945e75c0e3202ab4cd0b8f185ea4be5609806edb Mon Sep 17 00:00:00 2001
From: Nicolas Palix <npalix@diku.dk>
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>

Signed-off-by: Nicolas Palix <npalix@diku.dk>
---
 arch/sh/kernel/cpu/irq/ipr.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/sh/kernel/cpu/irq/ipr.c b/arch/sh/kernel/cpu/irq/ipr.c
index c1508a9..9282d96 100644
--- a/arch/sh/kernel/cpu/irq/ipr.c
+++ b/arch/sh/kernel/cpu/irq/ipr.c
@@ -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)
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] arch/sh: Replace an explicit computation by the use of the container_of macro
  2009-12-07  9:46 [PATCH] arch/sh: Replace an explicit computation by the use of the container_of macro Nicolas Palix
@ 2009-12-09  3:44 ` Paul Mundt
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Mundt @ 2009-12-09  3:44 UTC (permalink / raw)
  To: Nicolas Palix; +Cc: kernel-janitors, Stuart Menefy, linux-sh, linux-kernel

On Mon, Dec 07, 2009 at 10:46:26AM +0100, Nicolas Palix wrote:
> From 945e75c0e3202ab4cd0b8f185ea4be5609806edb Mon Sep 17 00:00:00 2001
> From: Nicolas Palix <npalix@diku.dk>
> 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>
> 
> Signed-off-by: Nicolas Palix <npalix@diku.dk>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-12-09  3:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-07  9:46 [PATCH] arch/sh: Replace an explicit computation by the use of the container_of macro Nicolas Palix
2009-12-09  3:44 ` Paul Mundt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).