Re: [PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-07-03 Thread Lee Jones
On Tue, 02 Jul 2019, Lothar Waßmann wrote:

> Hi,
> 
> On Tue, 2 Jul 2019 19:47:16 +0800 Fuqian Huang wrote:
> > Andy Shevchenko  於 2019年7月2日週二 下午5:51寫道:
> > >
> > > On Tue, Jul 2, 2019 at 11:20 AM Fuqian Huang  
> > > wrote:  
> > > >
> > > > I am not an expert on this. I just write a coccinelle script to search
> > > > this kind of misuse and fix it in a naive way.
> > > > Could you tell me about how to use the proper bus accessors? Then I
> > > > will fix it up and resend a v2 patch set.  
> > >
> > > First, don't top post.
> > > And answering to this, simple drop the patch.
> > > Proper bus accessors is exactly what it's used in the current code.  
> > 
> > But why not use dev_get_drvdata directly.
> > It simplifies getting the 'driver_data' from 'struct device' directly.
> > And the platform_device here is not required.
> > Replace it can remove the unnecessary step back and forth. (dev -> pdev -> 
> > dev).
> > 
> Did you check whether the compiler generates different (better) code
> with and without your patch? My guess is it won't.

I can see Fuqian's point.  If bus APIs are preferred, maybe it would
be nicer if the function was adapted to accept a platform_device
instead?

Caveat: I haven't taken the time to look into the call-site details.
This comment is based on just the patch alone.

-- 
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog


Re: [PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-07-02 Thread Lothar Waßmann
Hi,

On Tue, 2 Jul 2019 19:47:16 +0800 Fuqian Huang wrote:
> Andy Shevchenko  於 2019年7月2日週二 下午5:51寫道:
> >
> > On Tue, Jul 2, 2019 at 11:20 AM Fuqian Huang  
> > wrote:  
> > >
> > > I am not an expert on this. I just write a coccinelle script to search
> > > this kind of misuse and fix it in a naive way.
> > > Could you tell me about how to use the proper bus accessors? Then I
> > > will fix it up and resend a v2 patch set.  
> >
> > First, don't top post.
> > And answering to this, simple drop the patch.
> > Proper bus accessors is exactly what it's used in the current code.  
> 
> But why not use dev_get_drvdata directly.
> It simplifies getting the 'driver_data' from 'struct device' directly.
> And the platform_device here is not required.
> Replace it can remove the unnecessary step back and forth. (dev -> pdev -> 
> dev).
> 
Did you check whether the compiler generates different (better) code
with and without your patch? My guess is it won't.


Lothar Waßmann


Re: [PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-07-02 Thread Andy Shevchenko
On Tue, Jul 2, 2019 at 2:47 PM Fuqian Huang  wrote:
>
> Andy Shevchenko  於 2019年7月2日週二 下午5:51寫道:
> >
> > On Tue, Jul 2, 2019 at 11:20 AM Fuqian Huang  
> > wrote:
> > >
> > > I am not an expert on this. I just write a coccinelle script to search
> > > this kind of misuse and fix it in a naive way.
> > > Could you tell me about how to use the proper bus accessors? Then I
> > > will fix it up and resend a v2 patch set.
> >
> > First, don't top post.
> > And answering to this, simple drop the patch.
> > Proper bus accessors is exactly what it's used in the current code.
>
> But why not use dev_get_drvdata directly.
> It simplifies getting the 'driver_data' from 'struct device' directly.
> And the platform_device here is not required.
> Replace it can remove the unnecessary step back and forth. (dev -> pdev -> 
> dev).

Like just now Lothar gives a good idea for you to sell is to check
compiler output.

But the question itself is addressed to subsystem maintainer.

> Just like the commit

> 1948d498dcf6("thermal: intel: int340x: processor_thermal_device:
> simplify to get driver data")

Side note: this example is not good, since the macro is bus agnostic.

> and many other similar commits in the Linux git log.

-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-07-02 Thread Fuqian Huang
Andy Shevchenko  於 2019年7月2日週二 下午5:51寫道:
>
> On Tue, Jul 2, 2019 at 11:20 AM Fuqian Huang  wrote:
> >
> > I am not an expert on this. I just write a coccinelle script to search
> > this kind of misuse and fix it in a naive way.
> > Could you tell me about how to use the proper bus accessors? Then I
> > will fix it up and resend a v2 patch set.
>
> First, don't top post.
> And answering to this, simple drop the patch.
> Proper bus accessors is exactly what it's used in the current code.

But why not use dev_get_drvdata directly.
It simplifies getting the 'driver_data' from 'struct device' directly.
And the platform_device here is not required.
Replace it can remove the unnecessary step back and forth. (dev -> pdev -> dev).

Just like the commit
ed835136ee67 ("mfd: Use dev_get_drvdata() directly")
1948d498dcf6("thermal: intel: int340x: processor_thermal_device:
simplify to get driver data")
and many other similar commits in the Linux git log.


Re: [PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-07-02 Thread Andy Shevchenko
On Tue, Jul 2, 2019 at 11:20 AM Fuqian Huang  wrote:
>
> I am not an expert on this. I just write a coccinelle script to search
> this kind of misuse and fix it in a naive way.
> Could you tell me about how to use the proper bus accessors? Then I
> will fix it up and resend a v2 patch set.

First, don't top post.
And answering to this, simple drop the patch.
Proper bus accessors is exactly what it's used in the current code.


-- 
With Best Regards,
Andy Shevchenko


Re: [PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-07-02 Thread Fuqian Huang
I am not an expert on this. I just write a coccinelle script to search
this kind of misuse and fix it in a naive way.
Could you tell me about how to use the proper bus accessors? Then I
will fix it up and resend a v2 patch set.

Thanks.

Dmitry Torokhov  於 2019年7月1日週一 下午3:52寫道:
>
> Hi Fuqian,
>
> On Mon, Jul 01, 2019 at 11:23:12AM +0800, Fuqian Huang wrote:
> > Using dev_get_drvdata directly.
> >
>
> I prefer using proper bus accessors.
>
> Thanks.
>
> --
> Dmitry


Re: [PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-07-01 Thread Dmitry Torokhov
Hi Fuqian,

On Mon, Jul 01, 2019 at 11:23:12AM +0800, Fuqian Huang wrote:
> Using dev_get_drvdata directly.
> 

I prefer using proper bus accessors.

Thanks.

-- 
Dmitry


[PATCH 2/4] input: keyboard/mouse/touchscreen/misc: Use dev_get_drvdata()

2019-06-30 Thread Fuqian Huang
Using dev_get_drvdata directly.

Signed-off-by: Fuqian Huang 
---
 drivers/input/keyboard/ep93xx_keypad.c   | 10 --
 drivers/input/keyboard/gpio_keys.c   |  3 +--
 drivers/input/keyboard/imx_keypad.c  | 10 --
 drivers/input/keyboard/lpc32xx-keys.c|  6 ++
 drivers/input/keyboard/matrix_keypad.c   | 10 --
 drivers/input/keyboard/omap4-keypad.c| 10 --
 drivers/input/keyboard/pmic8xxx-keypad.c |  6 ++
 drivers/input/keyboard/pxa27x_keypad.c   | 10 --
 drivers/input/keyboard/samsung-keypad.c  | 12 
 drivers/input/keyboard/spear-keyboard.c  | 10 --
 drivers/input/keyboard/st-keyscan.c  |  6 ++
 drivers/input/keyboard/tegra-kbc.c   | 10 --
 drivers/input/misc/gpio-vibra.c  |  6 ++
 drivers/input/misc/max77693-haptic.c |  6 ++
 drivers/input/misc/max8925_onkey.c   | 10 --
 drivers/input/misc/max8997_haptic.c  |  3 +--
 drivers/input/misc/msm-vibrator.c|  6 ++
 drivers/input/misc/palmas-pwrbutton.c|  6 ++
 drivers/input/misc/regulator-haptic.c|  6 ++
 drivers/input/misc/stpmic1_onkey.c   |  6 ++
 drivers/input/misc/twl4030-vibra.c   |  3 +--
 drivers/input/misc/twl6040-vibra.c   |  3 +--
 drivers/input/mouse/navpoint.c   |  6 ++
 drivers/input/touchscreen/imx6ul_tsc.c   |  6 ++
 24 files changed, 62 insertions(+), 108 deletions(-)

diff --git a/drivers/input/keyboard/ep93xx_keypad.c 
b/drivers/input/keyboard/ep93xx_keypad.c
index 7c70492d9d6b..bcc8a17f9a01 100644
--- a/drivers/input/keyboard/ep93xx_keypad.c
+++ b/drivers/input/keyboard/ep93xx_keypad.c
@@ -178,8 +178,7 @@ static void ep93xx_keypad_close(struct input_dev *pdev)
 #ifdef CONFIG_PM_SLEEP
 static int ep93xx_keypad_suspend(struct device *dev)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct ep93xx_keypad *keypad = platform_get_drvdata(pdev);
+   struct ep93xx_keypad *keypad = dev_get_drvdata(dev);
struct input_dev *input_dev = keypad->input_dev;
 
mutex_lock(_dev->mutex);
@@ -191,7 +190,7 @@ static int ep93xx_keypad_suspend(struct device *dev)
 
mutex_unlock(_dev->mutex);
 
-   if (device_may_wakeup(>dev))
+   if (device_may_wakeup(dev))
enable_irq_wake(keypad->irq);
 
return 0;
@@ -199,11 +198,10 @@ static int ep93xx_keypad_suspend(struct device *dev)
 
 static int ep93xx_keypad_resume(struct device *dev)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct ep93xx_keypad *keypad = platform_get_drvdata(pdev);
+   struct ep93xx_keypad *keypad = dev_get_drvdata(dev);
struct input_dev *input_dev = keypad->input_dev;
 
-   if (device_may_wakeup(>dev))
+   if (device_may_wakeup(dev))
disable_irq_wake(keypad->irq);
 
mutex_lock(_dev->mutex);
diff --git a/drivers/input/keyboard/gpio_keys.c 
b/drivers/input/keyboard/gpio_keys.c
index a23c23979a2e..83d66155ce74 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -290,8 +290,7 @@ static ssize_t gpio_keys_show_##name(struct device *dev,
\
 struct device_attribute *attr, \
 char *buf) \
 {  \
-   struct platform_device *pdev = to_platform_device(dev); \
-   struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);   \
+   struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); \
\
return gpio_keys_attr_show_helper(ddata, buf,   \
  type, only_disabled); \
diff --git a/drivers/input/keyboard/imx_keypad.c 
b/drivers/input/keyboard/imx_keypad.c
index ae9c51cc85f9..d820de0908db 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -528,8 +528,7 @@ static int imx_keypad_probe(struct platform_device *pdev)
 
 static int __maybe_unused imx_kbd_noirq_suspend(struct device *dev)
 {
-   struct platform_device *pdev = to_platform_device(dev);
-   struct imx_keypad *kbd = platform_get_drvdata(pdev);
+   struct imx_keypad *kbd = dev_get_drvdata(dev);
struct input_dev *input_dev = kbd->input_dev;
unsigned short reg_val = readw(kbd->mmio_base + KPSR);
 
@@ -541,7 +540,7 @@ static int __maybe_unused imx_kbd_noirq_suspend(struct 
device *dev)
 
mutex_unlock(_dev->mutex);
 
-   if (device_may_wakeup(>dev)) {
+   if (device_may_wakeup(dev)) {
if (reg_val & KBD_STAT_KPKD)
reg_val |= KBD_STAT_KRIE;
if (reg_val & KBD_STAT_KPKR)
@@ -556,12 +555,11 @@ static int __maybe_unused imx_kbd_noirq_suspend(struct 
device *dev)
 
 static int __maybe_unused