diff mbox

[RESEND,v2,1/2] Input: touchscreen: ads7846: keep copy of pdata in private struct

Message ID 20130701013324.GA10755@core.coreip.homeip.net (mailing list archive)
State New, archived
Headers show

Commit Message

Dmitry Torokhov July 1, 2013, 1:33 a.m. UTC
Hi Daniel,

On Sun, Jun 30, 2013 at 11:09:14PM +0200, Daniel Mack wrote:
> +
> +	if (!pdata->model)
> +		pdata->model = 7846;
> +
> +	if (!pdata->vref_delay_usecs)
> +		pdata->vref_delay_usecs = 100;
> +
> +	if (!pdata->x_plate_ohms)
> +		pdata->x_plate_ohms = 400;
> +
> +	if (!pdata->pressure_max)
> +		pdata->pressure_max = ~0;

We should not be changing the platform data as the device does not own
it and it may well be declared as a constant structure.

In fact, I have a patch that declares pdata pointer as const.

Comments

Daniel Mack July 1, 2013, 6:48 a.m. UTC | #1
Hi Dmitry,

On 01.07.2013 03:33, Dmitry Torokhov wrote:
> On Sun, Jun 30, 2013 at 11:09:14PM +0200, Daniel Mack wrote:
>> +
>> +	if (!pdata->model)
>> +		pdata->model = 7846;
>> +
>> +	if (!pdata->vref_delay_usecs)
>> +		pdata->vref_delay_usecs = 100;
>> +
>> +	if (!pdata->x_plate_ohms)
>> +		pdata->x_plate_ohms = 400;
>> +
>> +	if (!pdata->pressure_max)
>> +		pdata->pressure_max = ~0;
> 
> We should not be changing the platform data as the device does not own
> it and it may well be declared as a constant structure.

We don't change the platform data that is passed in via the driver core.
We keep a copy of it in our private strucz (that's what the subject
says) and in case of DT, we modify that copy. The passed pdata is left
untouched.



Thanks,
Daniel

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov July 1, 2013, 7:09 a.m. UTC | #2
Hi Daniel,

On Mon, Jul 01, 2013 at 08:48:50AM +0200, Daniel Mack wrote:
> Hi Dmitry,
> 
> On 01.07.2013 03:33, Dmitry Torokhov wrote:
> > On Sun, Jun 30, 2013 at 11:09:14PM +0200, Daniel Mack wrote:
> >> +
> >> +	if (!pdata->model)
> >> +		pdata->model = 7846;
> >> +
> >> +	if (!pdata->vref_delay_usecs)
> >> +		pdata->vref_delay_usecs = 100;
> >> +
> >> +	if (!pdata->x_plate_ohms)
> >> +		pdata->x_plate_ohms = 400;
> >> +
> >> +	if (!pdata->pressure_max)
> >> +		pdata->pressure_max = ~0;
> > 
> > We should not be changing the platform data as the device does not own
> > it and it may well be declared as a constant structure.
> 
> We don't change the platform data that is passed in via the driver core.
> We keep a copy of it in our private strucz (that's what the subject
> says) and in case of DT, we modify that copy. The passed pdata is left
> untouched.
> 

That might have been the intent but the patch only stores a _pointer_ to
the platform data in the main structure, so in non-DT case you end up
modifying the original structure.

Thanks.
Daniel Mack July 1, 2013, 7:14 a.m. UTC | #3
On 01.07.2013 09:09, Dmitry Torokhov wrote:
> Hi Daniel,
> 
> On Mon, Jul 01, 2013 at 08:48:50AM +0200, Daniel Mack wrote:
>> Hi Dmitry,
>>
>> On 01.07.2013 03:33, Dmitry Torokhov wrote:
>>> On Sun, Jun 30, 2013 at 11:09:14PM +0200, Daniel Mack wrote:
>>>> +
>>>> +	if (!pdata->model)
>>>> +		pdata->model = 7846;
>>>> +
>>>> +	if (!pdata->vref_delay_usecs)
>>>> +		pdata->vref_delay_usecs = 100;
>>>> +
>>>> +	if (!pdata->x_plate_ohms)
>>>> +		pdata->x_plate_ohms = 400;
>>>> +
>>>> +	if (!pdata->pressure_max)
>>>> +		pdata->pressure_max = ~0;
>>>
>>> We should not be changing the platform data as the device does not own
>>> it and it may well be declared as a constant structure.
>>
>> We don't change the platform data that is passed in via the driver core.
>> We keep a copy of it in our private strucz (that's what the subject
>> says) and in case of DT, we modify that copy. The passed pdata is left
>> untouched.
>>
> 
> That might have been the intent but the patch only stores a _pointer_ to
> the platform data in the main structure, so in non-DT case you end up
> modifying the original structure.

Eh, ok. I'll change that to always make a copy. Somehow though, I like
the first approach (v1 of the set) better, which stored all data that is
modified inside the private struct directly.

Anyway, I'll submit v3 later.


Thanks,
Daniel

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov July 1, 2013, 7:21 a.m. UTC | #4
On Mon, Jul 01, 2013 at 09:14:04AM +0200, Daniel Mack wrote:
> On 01.07.2013 09:09, Dmitry Torokhov wrote:
> > Hi Daniel,
> > 
> > On Mon, Jul 01, 2013 at 08:48:50AM +0200, Daniel Mack wrote:
> >> Hi Dmitry,
> >>
> >> On 01.07.2013 03:33, Dmitry Torokhov wrote:
> >>> On Sun, Jun 30, 2013 at 11:09:14PM +0200, Daniel Mack wrote:
> >>>> +
> >>>> +	if (!pdata->model)
> >>>> +		pdata->model = 7846;
> >>>> +
> >>>> +	if (!pdata->vref_delay_usecs)
> >>>> +		pdata->vref_delay_usecs = 100;
> >>>> +
> >>>> +	if (!pdata->x_plate_ohms)
> >>>> +		pdata->x_plate_ohms = 400;
> >>>> +
> >>>> +	if (!pdata->pressure_max)
> >>>> +		pdata->pressure_max = ~0;
> >>>
> >>> We should not be changing the platform data as the device does not own
> >>> it and it may well be declared as a constant structure.
> >>
> >> We don't change the platform data that is passed in via the driver core.
> >> We keep a copy of it in our private strucz (that's what the subject
> >> says) and in case of DT, we modify that copy. The passed pdata is left
> >> untouched.
> >>
> > 
> > That might have been the intent but the patch only stores a _pointer_ to
> > the platform data in the main structure, so in non-DT case you end up
> > modifying the original structure.
> 
> Eh, ok. I'll change that to always make a copy. Somehow though, I like
> the first approach (v1 of the set) better, which stored all data that is
> modified inside the private struct directly.
> 
> Anyway, I'll submit v3 later.

No, there is no need, the other patch (adding DT bindings) should work
just fine without this one.

Thanks.
diff mbox

Patch

diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 84ccf14..5ff0419 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -961,9 +961,9 @@  static int ads7846_resume(struct device *dev)
 static SIMPLE_DEV_PM_OPS(ads7846_pm, ads7846_suspend, ads7846_resume);
 
 static int ads7846_setup_pendown(struct spi_device *spi,
-					   struct ads7846 *ts)
+				 struct ads7846 *ts,
+				 const struct ads7846_platform_data *pdata)
 {
-	struct ads7846_platform_data *pdata = spi->dev.platform_data;
 	int err;
 
 	/*
@@ -1003,7 +1003,7 @@  static int ads7846_setup_pendown(struct spi_device *spi,
  * use formula #2 for pressure, not #3.
  */
 static void ads7846_setup_spi_msg(struct ads7846 *ts,
-				const struct ads7846_platform_data *pdata)
+				  const struct ads7846_platform_data *pdata)
 {
 	struct spi_message *m = &ts->msg[0];
 	struct spi_transfer *x = ts->xfer;
@@ -1203,10 +1203,10 @@  static void ads7846_setup_spi_msg(struct ads7846 *ts,
 
 static int ads7846_probe(struct spi_device *spi)
 {
+	const struct ads7846_platform_data *pdata = dev_get_platdata(&spi->dev);
 	struct ads7846 *ts;
 	struct ads7846_packet *packet;
 	struct input_dev *input_dev;
-	struct ads7846_platform_data *pdata = spi->dev.platform_data;
 	unsigned long irq_flags;
 	int err;
 
@@ -1281,7 +1281,7 @@  static int ads7846_probe(struct spi_device *spi)
 		ts->filter = ads7846_no_filter;
 	}
 
-	err = ads7846_setup_pendown(spi, ts);
+	err = ads7846_setup_pendown(spi, ts, pdata);
 	if (err)
 		goto err_cleanup_filter;