mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: kernel@pengutronix.de
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH 2/2] Driver core: add typechecking to platform_{get,set}_drvdata
Date: Wed, 16 Feb 2011 22:55:51 +0100	[thread overview]
Message-ID: <1297893351-2900-3-git-send-email-mkl@pengutronix.de> (raw)
In-Reply-To: <1297893351-2900-1-git-send-email-mkl@pengutronix.de>

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


  parent reply	other threads:[~2011-02-16 21:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16 21:55 [PATCH 0/2] RFC: introduce " 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 [this message]
2011-02-16 22:02 ` [PATCH 0/2] RFC: introduce typechecking to platform_{get,set}_drvdata Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1297893351-2900-3-git-send-email-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@suse.de \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®