public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata
@ 2011-02-16 21:55 Marc Kleine-Budde
  2011-02-16 21:55 ` [PATCH 1/2] kernel.h: introduce BUILD_BUG_ON_NOT_SAME_TYPE Marc Kleine-Budde
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2011-02-16 21:55 UTC (permalink / raw)
  To: kernel; +Cc: Greg Kroah-Hartman, Andrew Morton, linux-kernel

Hello,

just found a mis-user of platform_set_drvdata(), so introduce typechecking
to these macro definitions. An alternative would be to make them static inline
functions.

comments welcome,
Marc



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

* [PATCH 1/2] kernel.h: introduce BUILD_BUG_ON_NOT_SAME_TYPE
  2011-02-16 21:55 [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata Marc Kleine-Budde
@ 2011-02-16 21:55 ` Marc Kleine-Budde
  2011-02-16 21:55 ` [PATCH 2/2] Driver core: add typechecking to platform_{get,set}_drvdata Marc Kleine-Budde
  2011-02-16 22:02 ` [PATCH 0/2] RFC: introduce " Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2011-02-16 21:55 UTC (permalink / raw)
  To: kernel; +Cc: Greg Kroah-Hartman, Andrew Morton, linux-kernel,
	Marc Kleine-Budde

This patch introduces BUILD_BUG_ON_NOT_SAME_TYPE which forces a compilation
error if the two supplied variables don't have the same type.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 include/linux/kernel.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2fe6e84..b637d57 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -612,6 +612,8 @@ extern int __build_bug_on_failed;
 	} while(0)
 #endif
 
+#define BUILD_BUG_ON_NOT_SAME_TYPE(a, b) BUILD_BUG_ON(!__same_type((a), (b)));
+
 /* Trap pasters of __FUNCTION__ at compile-time */
 #define __FUNCTION__ (__func__)
 
-- 
1.7.2.3


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

* [PATCH 2/2] Driver core: add typechecking to platform_{get,set}_drvdata
  2011-02-16 21:55 [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata Marc Kleine-Budde
  2011-02-16 21:55 ` [PATCH 1/2] kernel.h: introduce BUILD_BUG_ON_NOT_SAME_TYPE Marc Kleine-Budde
@ 2011-02-16 21:55 ` Marc Kleine-Budde
  2011-02-16 22:02 ` [PATCH 0/2] RFC: introduce " Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2011-02-16 21:55 UTC (permalink / raw)
  To: kernel; +Cc: Greg Kroah-Hartman, Andrew Morton, linux-kernel,
	Marc Kleine-Budde

Use the previously introduced BUILD_BUG_ON_NOT_SAME_TYPE to check if the
dev argument is a struct platform_device pointer.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 include/linux/platform_device.h |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 2e700ec..761a917 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -130,8 +130,14 @@ extern void platform_driver_unregister(struct platform_driver *);
 extern int platform_driver_probe(struct platform_driver *driver,
 		int (*probe)(struct platform_device *));
 
-#define platform_get_drvdata(_dev)	dev_get_drvdata(&(_dev)->dev)
-#define platform_set_drvdata(_dev,data)	dev_set_drvdata(&(_dev)->dev, (data))
+#define platform_get_drvdata(_dev)	({ \
+	BUILD_BUG_ON_NOT_SAME_TYPE((_dev), (struct platform_device *)NULL); \
+	dev_get_drvdata(&(_dev)->dev); \
+})
+#define platform_set_drvdata(_dev,data)	({ \
+	BUILD_BUG_ON_NOT_SAME_TYPE((_dev), (struct platform_device *)NULL); \
+	dev_set_drvdata(&(_dev)->dev, (data)); \
+})
 
 extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
 					int (*probe)(struct platform_device *),
-- 
1.7.2.3


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

* Re: [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata
       [not found] ` <20110216135547.8940e19d.akpm@linux-foundation.org>
@ 2011-02-16 21:59   ` Marc Kleine-Budde
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2011-02-16 21:59 UTC (permalink / raw)
  To: Andrew Morton; +Cc: kernel, Greg Kroah-Hartman, LKML

[-- Attachment #1: Type: text/plain, Size: 1126 bytes --]

On 02/16/2011 10:55 PM, Andrew Morton wrote:
> On Wed, 16 Feb 2011 22:49:52 +0100
> Marc Kleine-Budde <mkl@pengutronix.de> wrote:
> 
>> From: Marc Kleine-Budde <mkl@pengutronix.de>
>> To: kernel@pengutronix.de
>> Cc: Greg Kroah-Hartman <gregkh@suse.de>, Andrew Morton <akpm@linux-foundation.org>
> 
> No mailing list was cc'ed.

just noticed, sorry :(

>> Subject: [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata
>> Date: Wed, 16 Feb 2011 22:49:52 +0100
>> X-Mailer: git-send-email 1.7.2.3
>>
>> Hello,
>>
>> just found a mis-user of platform_set_drvdata(), so introduce typechecking
>> to these macro definitions.
> 
> ick.
> 
>> An alternative would be to make them static inline
>> functions.
> 
> A vastly preferable alternative!  How's about doing that?

Sure...wait for "v2"

regards, Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

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

* Re: [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata
  2011-02-16 21:55 [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata Marc Kleine-Budde
  2011-02-16 21:55 ` [PATCH 1/2] kernel.h: introduce BUILD_BUG_ON_NOT_SAME_TYPE Marc Kleine-Budde
  2011-02-16 21:55 ` [PATCH 2/2] Driver core: add typechecking to platform_{get,set}_drvdata Marc Kleine-Budde
@ 2011-02-16 22:02 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2011-02-16 22:02 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: kernel, Andrew Morton, linux-kernel

On Wed, Feb 16, 2011 at 10:55:49PM +0100, Marc Kleine-Budde wrote:
> Hello,
> 
> just found a mis-user of platform_set_drvdata(), so introduce typechecking
> to these macro definitions. An alternative would be to make them static inline
> functions.

Make it a static inline, that way you don't have to create that new
macro, as the build will warn/break right away.

thanks,

greg k-h

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

end of thread, other threads:[~2011-02-16 22:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-16 21:55 [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata Marc Kleine-Budde
2011-02-16 21:55 ` [PATCH 1/2] kernel.h: introduce BUILD_BUG_ON_NOT_SAME_TYPE Marc Kleine-Budde
2011-02-16 21:55 ` [PATCH 2/2] Driver core: add typechecking to platform_{get,set}_drvdata Marc Kleine-Budde
2011-02-16 22:02 ` [PATCH 0/2] RFC: introduce " Greg KH
     [not found] <1297892994-30801-1-git-send-email-mkl@pengutronix.de>
     [not found] ` <20110216135547.8940e19d.akpm@linux-foundation.org>
2011-02-16 21:59   ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox