All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Christopher Heiny <cheiny@synaptics.com>
Cc: Andrew Duggan <aduggan@synaptics.com>,
	Vincent Huang <vincent.huang@tw.synaptics.com>,
	Vivian Ly <vly@synaptics.com>,
	Daniel Rosenberg <daniel.rosenberg@synaptics.com>,
	Linus Walleij <linus.walleij@stericsson.com>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Courtney Cavin <courtney.cavin@sonymobile.com>,
	Linux Input <linux-input@vger.kernel.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH 10/11] Input: synaptics-rmi4 - make accessor for platform data return const pointer
Date: Wed, 12 Feb 2014 21:27:56 -0800	[thread overview]
Message-ID: <1392269277-16391-10-git-send-email-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <1392269277-16391-1-git-send-email-dmitry.torokhov@gmail.com>

When accessing platform data of RMI device let's make sure we do not
accidentally change data that may be shared by returning const pointer.
Also switch to an inline function instead of macro to ensure type safety.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/rmi4/rmi_bus.h    | 7 ++++++-
 drivers/input/rmi4/rmi_driver.c | 8 ++++----
 drivers/input/rmi4/rmi_f01.c    | 2 +-
 drivers/input/rmi4/rmi_f11.c    | 2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/input/rmi4/rmi_bus.h b/drivers/input/rmi4/rmi_bus.h
index 8d47f52..02a2af8 100644
--- a/drivers/input/rmi4/rmi_bus.h
+++ b/drivers/input/rmi4/rmi_bus.h
@@ -224,7 +224,12 @@ struct rmi_device {
 };
 
 #define to_rmi_device(d) container_of(d, struct rmi_device, dev)
-#define to_rmi_platform_data(d) ((d)->xport->dev->platform_data)
+
+static inline const struct rmi_device_platform_data *
+rmi_get_platform_data(struct rmi_device *d)
+{
+	return dev_get_platdata(d->xport->dev);
+}
 
 bool rmi_is_physical_device(struct device *dev);
 
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 736cfbd..473efbc 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -598,7 +598,7 @@ static int rmi_initial_reset(struct rmi_device *rmi_dev,
 		u16 cmd_addr = pdt->page_start + pdt->command_base_addr;
 		u8 cmd_buf = RMI_DEVICE_RESET_CMD;
 		const struct rmi_device_platform_data *pdata =
-				to_rmi_platform_data(rmi_dev);
+				rmi_get_platform_data(rmi_dev);
 
 		error = rmi_write_block(rmi_dev, cmd_addr, &cmd_buf, 1);
 		if (error) {
@@ -621,7 +621,7 @@ static int rmi_create_function(struct rmi_device *rmi_dev,
 {
 	struct device *dev = &rmi_dev->dev;
 	struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
-	struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);
+	const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
 	int *current_irq_count = ctx;
 	struct rmi_function *fn;
 	int i;
@@ -745,7 +745,7 @@ static int rmi_driver_remove(struct device *dev)
 	struct rmi_device *rmi_dev = to_rmi_device(dev);
 	struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
 	const struct rmi_device_platform_data *pdata =
-					to_rmi_platform_data(rmi_dev);
+					rmi_get_platform_data(rmi_dev);
 
 	disable_sensor(rmi_dev);
 	rmi_free_function_list(rmi_dev);
@@ -781,7 +781,7 @@ static int rmi_driver_probe(struct device *dev)
 	rmi_driver = to_rmi_driver(dev->driver);
 	rmi_dev->driver = rmi_driver;
 
-	pdata = to_rmi_platform_data(rmi_dev);
+	pdata = rmi_get_platform_data(rmi_dev);
 
 	data = devm_kzalloc(dev, sizeof(struct rmi_driver_data), GFP_KERNEL);
 	if (!data) {
diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
index 0e21004..36fcf8d 100644
--- a/drivers/input/rmi4/rmi_f01.c
+++ b/drivers/input/rmi4/rmi_f01.c
@@ -184,7 +184,7 @@ static int rmi_f01_probe(struct rmi_function *fn)
 {
 	struct rmi_device *rmi_dev = fn->rmi_dev;
 	struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
-	const struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);
+	const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
 	struct f01_data *f01;
 	size_t f01_size;
 	int error;
diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c
index 2aa7d17..5072437 100644
--- a/drivers/input/rmi4/rmi_f11.c
+++ b/drivers/input/rmi4/rmi_f11.c
@@ -1176,7 +1176,7 @@ static int rmi_f11_initialize(struct rmi_function *fn)
 	u16 control_base_addr;
 	u16 max_x_pos, max_y_pos, temp;
 	int rc;
-	struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);
+	const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
 	struct f11_2d_sensor *sensor;
 	u8 buf;
 
-- 
1.8.5.3


  parent reply	other threads:[~2014-02-13  5:28 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13  5:27 [PATCH 01/11] Input: synaptics-rmi4 - do not kfree() managed memory in F01 Dmitry Torokhov
2014-02-13  5:27 ` [PATCH 02/11] Input: synaptics-rmi4 - remove unused rmi_f01_remove() Dmitry Torokhov
2014-02-13 19:11   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 03/11] Input: synaptics-rmi4 - do not update configuration in rmi_f01_probe() Dmitry Torokhov
2014-02-13 19:23   ` Christopher Heiny
2014-02-13 21:54     ` Dmitry Torokhov
2014-02-14 23:00       ` Christopher Heiny
2014-02-17 19:23         ` Dmitry Torokhov
2014-02-18 21:32           ` Christopher Heiny
2014-03-19  0:21   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 04/11] Input: synaptics-rmi4 - fix LTS handling in F01 Dmitry Torokhov
2014-02-13 19:32   ` Christopher Heiny
2014-02-14  8:05     ` Dmitry Torokhov
2014-02-13  5:27 ` [PATCH 05/11] Input: synaptics-rmi4 - remove control_mutex from f01_data Dmitry Torokhov
2014-02-13 23:01   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 06/11] Input: synaptics-rmi4 - remove device_status form f01_data Dmitry Torokhov
2014-02-13 21:15   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 07/11] Input: synaptics-rmi4 - rename instances of f01_data from data to f01 Dmitry Torokhov
2014-02-13 21:32   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 08/11] Input: synaptics-rmi4 - use rmi_read/rmi_write in F01 Dmitry Torokhov
2014-02-13 21:33   ` Christopher Heiny
2014-02-13  5:27 ` [PATCH 09/11] Input: synaptics-rmi4 - consolidate memory allocations " Dmitry Torokhov
2014-02-13 19:52   ` Christopher Heiny
2014-02-13  5:27 ` Dmitry Torokhov [this message]
2014-02-13 20:00   ` [PATCH 10/11] Input: synaptics-rmi4 - make accessor for platform data return const pointer Christopher Heiny
2014-02-13  5:27 ` [PATCH 11/11] Input: synaptics-rmi4 - remove data pointer from RMI fucntion structure Dmitry Torokhov
2014-02-13 21:33   ` Christopher Heiny
2014-02-13 19:11 ` [PATCH 01/11] Input: synaptics-rmi4 - do not kfree() managed memory in F01 Christopher Heiny

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=1392269277-16391-10-git-send-email-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=aduggan@synaptics.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=cheiny@synaptics.com \
    --cc=courtney.cavin@sonymobile.com \
    --cc=daniel.rosenberg@synaptics.com \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vincent.huang@tw.synaptics.com \
    --cc=vly@synaptics.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.