2024-03-18 05:56:06

by Dhruva Gole

[permalink] [raw]
Subject: [PATCH 0/3] PM: wakeup: make device_wakeup_disable return void

This is a follow up patch based on discussions with Rafael[0] on a previous
patch I sent to propagate return value from device_wakeup_disable
further upward inside device_init_wakeup

However, it doesn't seem like today any return values from
device_wakeup_disable are very useful to the caller.

I could only spot one caller of this function that was actually
propagating the return value upward other than the PM core calls. I have
tried to update sdhci-pci-core to work with the new changes

I think that the patch 3/3 should go via Adrian or Ulf's tree, rest are
all PM core changes.

[0] https://lore.kernel.org/all/CAJZ5v0jbHwiZemtNAoM-jmgB_58VqmKUkqv4P7qrPkxWzBzMyQ@mail.gmail.com/

Dhruva Gole (3):
PM: wakeup: make device_wakeup_disable return void
PM: wakeup: Remove unnecessary else from device_init_wakeup
mmc: sdhci-pci: Use device_set_wakeup_enable for en/disable wakeups

drivers/base/power/wakeup.c | 11 +++++++----
drivers/mmc/host/sdhci-pci-core.c | 4 ++--
include/linux/pm_wakeup.h | 12 +++++-------
3 files changed, 14 insertions(+), 13 deletions(-)

--
2.34.1



2024-03-18 06:07:15

by Dhruva Gole

[permalink] [raw]
Subject: [PATCH 2/3] PM: wakeup: Remove unnecessary else from device_init_wakeup

Checkpatch warns that else is generally not necessary after a return
condition which exists in the if part of this function. Hence, just to
abide by what checkpatch recommends, follow it's guidelines.

Signed-off-by: Dhruva Gole <[email protected]>
---
include/linux/pm_wakeup.h | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index 428803eed798..76cd1f9f1365 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -234,11 +234,10 @@ static inline int device_init_wakeup(struct device *dev, bool enable)
if (enable) {
device_set_wakeup_capable(dev, true);
return device_wakeup_enable(dev);
- } else {
- device_wakeup_disable(dev);
- device_set_wakeup_capable(dev, false);
- return 0;
}
+ device_wakeup_disable(dev);
+ device_set_wakeup_capable(dev, false);
+ return 0;
}

#endif /* _LINUX_PM_WAKEUP_H */
--
2.34.1


2024-03-18 06:07:32

by Dhruva Gole

[permalink] [raw]
Subject: [PATCH 3/3] mmc: sdhci-pci: Use device_set_wakeup_enable for en/disable wakeups

There exists device_set_wakeup_enable for wrapping device_wakeup_enable
and device_wakeup_disable. Use that instead to avoid confusion in
returning from a void vs int function.

Signed-off-by: Dhruva Gole <[email protected]>
---

I do not have the hardware to test out this driver, hence requesting
someone to review/ test it if atall you suspect that this change can
break existing functionality.

drivers/mmc/host/sdhci-pci-core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 025b31aa712c..db614389a5fc 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -61,9 +61,9 @@ static int sdhci_pci_init_wakeup(struct sdhci_pci_chip *chip)
}

if ((pm_flags & MMC_PM_KEEP_POWER) && (pm_flags & MMC_PM_WAKE_SDIO_IRQ))
- return device_wakeup_enable(&chip->pdev->dev);
+ return device_set_wakeup_enable(&chip->pdev->dev, true);
else if (!cap_cd_wake)
- return device_wakeup_disable(&chip->pdev->dev);
+ return device_set_wakeup_enable(&chip->pdev->dev, false);

return 0;
}
--
2.34.1


2024-03-18 06:07:45

by Dhruva Gole

[permalink] [raw]
Subject: [PATCH 1/3] PM: wakeup: make device_wakeup_disable return void

The device_wakeup_disable call only returns an error if no dev exists
however there's not much a user can do at that point.
Rather make this function return void.

Signed-off-by: Dhruva Gole <[email protected]>
---
drivers/base/power/wakeup.c | 11 +++++++----
include/linux/pm_wakeup.h | 5 ++---
2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index a917219feea6..752b417e8129 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -451,16 +451,15 @@ static struct wakeup_source *device_wakeup_detach(struct device *dev)
* Detach the @dev's wakeup source object from it, unregister this wakeup source
* object and destroy it.
*/
-int device_wakeup_disable(struct device *dev)
+void device_wakeup_disable(struct device *dev)
{
struct wakeup_source *ws;

if (!dev || !dev->power.can_wakeup)
- return -EINVAL;
+ return;

ws = device_wakeup_detach(dev);
wakeup_source_unregister(ws);
- return 0;
}
EXPORT_SYMBOL_GPL(device_wakeup_disable);

@@ -502,7 +501,11 @@ EXPORT_SYMBOL_GPL(device_set_wakeup_capable);
*/
int device_set_wakeup_enable(struct device *dev, bool enable)
{
- return enable ? device_wakeup_enable(dev) : device_wakeup_disable(dev);
+ if (enable)
+ return device_wakeup_enable(dev);
+
+ device_wakeup_disable(dev);
+ return 0;
}
EXPORT_SYMBOL_GPL(device_set_wakeup_enable);

diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
index 6eb9adaef52b..428803eed798 100644
--- a/include/linux/pm_wakeup.h
+++ b/include/linux/pm_wakeup.h
@@ -107,7 +107,7 @@ extern void wakeup_sources_read_unlock(int idx);
extern struct wakeup_source *wakeup_sources_walk_start(void);
extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);
extern int device_wakeup_enable(struct device *dev);
-extern int device_wakeup_disable(struct device *dev);
+extern void device_wakeup_disable(struct device *dev);
extern void device_set_wakeup_capable(struct device *dev, bool capable);
extern int device_set_wakeup_enable(struct device *dev, bool enable);
extern void __pm_stay_awake(struct wakeup_source *ws);
@@ -154,10 +154,9 @@ static inline int device_wakeup_enable(struct device *dev)
return 0;
}

-static inline int device_wakeup_disable(struct device *dev)
+static inline void device_wakeup_disable(struct device *dev)
{
dev->power.should_wakeup = false;
- return 0;
}

static inline int device_set_wakeup_enable(struct device *dev, bool enable)
--
2.34.1


2024-03-18 13:48:09

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 1/3] PM: wakeup: make device_wakeup_disable return void

On Mon, Mar 18, 2024 at 6:55 AM Dhruva Gole <[email protected]> wrote:
>
> The device_wakeup_disable call only returns an error if no dev exists
> however there's not much a user can do at that point.
> Rather make this function return void.
>
> Signed-off-by: Dhruva Gole <[email protected]>
> ---
> drivers/base/power/wakeup.c | 11 +++++++----
> include/linux/pm_wakeup.h | 5 ++---
> 2 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> index a917219feea6..752b417e8129 100644
> --- a/drivers/base/power/wakeup.c
> +++ b/drivers/base/power/wakeup.c
> @@ -451,16 +451,15 @@ static struct wakeup_source *device_wakeup_detach(struct device *dev)
> * Detach the @dev's wakeup source object from it, unregister this wakeup source
> * object and destroy it.
> */
> -int device_wakeup_disable(struct device *dev)
> +void device_wakeup_disable(struct device *dev)
> {
> struct wakeup_source *ws;
>
> if (!dev || !dev->power.can_wakeup)
> - return -EINVAL;
> + return;
>
> ws = device_wakeup_detach(dev);
> wakeup_source_unregister(ws);
> - return 0;
> }
> EXPORT_SYMBOL_GPL(device_wakeup_disable);
>
> @@ -502,7 +501,11 @@ EXPORT_SYMBOL_GPL(device_set_wakeup_capable);
> */
> int device_set_wakeup_enable(struct device *dev, bool enable)
> {
> - return enable ? device_wakeup_enable(dev) : device_wakeup_disable(dev);
> + if (enable)
> + return device_wakeup_enable(dev);
> +
> + device_wakeup_disable(dev);
> + return 0;
> }
> EXPORT_SYMBOL_GPL(device_set_wakeup_enable);
>
> diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
> index 6eb9adaef52b..428803eed798 100644
> --- a/include/linux/pm_wakeup.h
> +++ b/include/linux/pm_wakeup.h
> @@ -107,7 +107,7 @@ extern void wakeup_sources_read_unlock(int idx);
> extern struct wakeup_source *wakeup_sources_walk_start(void);
> extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);
> extern int device_wakeup_enable(struct device *dev);
> -extern int device_wakeup_disable(struct device *dev);
> +extern void device_wakeup_disable(struct device *dev);

This change will introduce a build error in sdhci-pci-core.c AFAICS,
so you need to modify this file in the same patch to avoid bisection
breakage.

> extern void device_set_wakeup_capable(struct device *dev, bool capable);
> extern int device_set_wakeup_enable(struct device *dev, bool enable);
> extern void __pm_stay_awake(struct wakeup_source *ws);
> @@ -154,10 +154,9 @@ static inline int device_wakeup_enable(struct device *dev)
> return 0;
> }
>
> -static inline int device_wakeup_disable(struct device *dev)
> +static inline void device_wakeup_disable(struct device *dev)
> {
> dev->power.should_wakeup = false;
> - return 0;
> }
>
> static inline int device_set_wakeup_enable(struct device *dev, bool enable)
> --
> 2.34.1
>

2024-03-18 13:51:09

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 3/3] mmc: sdhci-pci: Use device_set_wakeup_enable for en/disable wakeups

On Mon, Mar 18, 2024 at 6:55 AM Dhruva Gole <[email protected]> wrote:
>
> There exists device_set_wakeup_enable for wrapping device_wakeup_enable
> and device_wakeup_disable. Use that instead to avoid confusion in
> returning from a void vs int function.
>
> Signed-off-by: Dhruva Gole <[email protected]>
> ---
>
> I do not have the hardware to test out this driver, hence requesting
> someone to review/ test it if atall you suspect that this change can
> break existing functionality.
>
> drivers/mmc/host/sdhci-pci-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
> index 025b31aa712c..db614389a5fc 100644
> --- a/drivers/mmc/host/sdhci-pci-core.c
> +++ b/drivers/mmc/host/sdhci-pci-core.c
> @@ -61,9 +61,9 @@ static int sdhci_pci_init_wakeup(struct sdhci_pci_chip *chip)
> }
>
> if ((pm_flags & MMC_PM_KEEP_POWER) && (pm_flags & MMC_PM_WAKE_SDIO_IRQ))
> - return device_wakeup_enable(&chip->pdev->dev);
> + return device_set_wakeup_enable(&chip->pdev->dev, true);

This change is not necessary.

> else if (!cap_cd_wake)
> - return device_wakeup_disable(&chip->pdev->dev);
> + return device_set_wakeup_enable(&chip->pdev->dev, false);

It would be sufficient to simply drop the return statement from here, that is

+ device_wakeup_disable(&chip->pdev->dev);

and it can be done in the first patch (which would be less confusing even IMO).

>
> return 0;
> }
> --

2024-03-18 13:52:24

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH 2/3] PM: wakeup: Remove unnecessary else from device_init_wakeup

On Mon, Mar 18, 2024 at 6:55 AM Dhruva Gole <[email protected]> wrote:
>
> Checkpatch warns that else is generally not necessary after a return
> condition which exists in the if part of this function. Hence, just to
> abide by what checkpatch recommends, follow it's guidelines.
>
> Signed-off-by: Dhruva Gole <[email protected]>
> ---
> include/linux/pm_wakeup.h | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
> index 428803eed798..76cd1f9f1365 100644
> --- a/include/linux/pm_wakeup.h
> +++ b/include/linux/pm_wakeup.h
> @@ -234,11 +234,10 @@ static inline int device_init_wakeup(struct device *dev, bool enable)
> if (enable) {
> device_set_wakeup_capable(dev, true);
> return device_wakeup_enable(dev);
> - } else {
> - device_wakeup_disable(dev);
> - device_set_wakeup_capable(dev, false);
> - return 0;
> }
> + device_wakeup_disable(dev);
> + device_set_wakeup_capable(dev, false);
> + return 0;
> }
>
> #endif /* _LINUX_PM_WAKEUP_H */
> --

This one is fine with me, but not 6.9-rc material.

Thanks!

2024-03-18 15:19:28

by Dhruva Gole

[permalink] [raw]
Subject: Re: [PATCH 2/3] PM: wakeup: Remove unnecessary else from device_init_wakeup

On Mar 18, 2024 at 14:52:02 +0100, Rafael J. Wysocki wrote:
> On Mon, Mar 18, 2024 at 6:55 AM Dhruva Gole <[email protected]> wrote:
> >
> > Checkpatch warns that else is generally not necessary after a return
> > condition which exists in the if part of this function. Hence, just to
> > abide by what checkpatch recommends, follow it's guidelines.
> >
> > Signed-off-by: Dhruva Gole <[email protected]>
> > ---
> > include/linux/pm_wakeup.h | 7 +++----
> > 1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
> > index 428803eed798..76cd1f9f1365 100644
> > --- a/include/linux/pm_wakeup.h
> > +++ b/include/linux/pm_wakeup.h
> > @@ -234,11 +234,10 @@ static inline int device_init_wakeup(struct device *dev, bool enable)
> > if (enable) {
> > device_set_wakeup_capable(dev, true);
> > return device_wakeup_enable(dev);
> > - } else {
> > - device_wakeup_disable(dev);
> > - device_set_wakeup_capable(dev, false);
> > - return 0;
> > }
> > + device_wakeup_disable(dev);
> > + device_set_wakeup_capable(dev, false);
> > + return 0;
> > }
> >
> > #endif /* _LINUX_PM_WAKEUP_H */
> > --
>
> This one is fine with me, but not 6.9-rc material.

OK, I completely understand.

--
Best regards,
Dhruva Gole <[email protected]>

2024-03-18 15:20:00

by Dhruva Gole

[permalink] [raw]
Subject: Re: [PATCH 1/3] PM: wakeup: make device_wakeup_disable return void

On Mar 18, 2024 at 14:47:45 +0100, Rafael J. Wysocki wrote:
> On Mon, Mar 18, 2024 at 6:55 AM Dhruva Gole <[email protected]> wrote:
> >
> > The device_wakeup_disable call only returns an error if no dev exists
> > however there's not much a user can do at that point.
> > Rather make this function return void.
> >
> > Signed-off-by: Dhruva Gole <[email protected]>
> > ---
> > drivers/base/power/wakeup.c | 11 +++++++----
> > include/linux/pm_wakeup.h | 5 ++---
> > 2 files changed, 9 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
> > index a917219feea6..752b417e8129 100644
> > --- a/drivers/base/power/wakeup.c
> > +++ b/drivers/base/power/wakeup.c
> > @@ -451,16 +451,15 @@ static struct wakeup_source *device_wakeup_detach(struct device *dev)
> > * Detach the @dev's wakeup source object from it, unregister this wakeup source
> > * object and destroy it.
> > */
> > -int device_wakeup_disable(struct device *dev)
> > +void device_wakeup_disable(struct device *dev)
> > {
> > struct wakeup_source *ws;
> >
> > if (!dev || !dev->power.can_wakeup)
> > - return -EINVAL;
> > + return;
> >
> > ws = device_wakeup_detach(dev);
> > wakeup_source_unregister(ws);
> > - return 0;
> > }
> > EXPORT_SYMBOL_GPL(device_wakeup_disable);
> >
> > @@ -502,7 +501,11 @@ EXPORT_SYMBOL_GPL(device_set_wakeup_capable);
> > */
> > int device_set_wakeup_enable(struct device *dev, bool enable)
> > {
> > - return enable ? device_wakeup_enable(dev) : device_wakeup_disable(dev);
> > + if (enable)
> > + return device_wakeup_enable(dev);
> > +
> > + device_wakeup_disable(dev);
> > + return 0;
> > }
> > EXPORT_SYMBOL_GPL(device_set_wakeup_enable);
> >
> > diff --git a/include/linux/pm_wakeup.h b/include/linux/pm_wakeup.h
> > index 6eb9adaef52b..428803eed798 100644
> > --- a/include/linux/pm_wakeup.h
> > +++ b/include/linux/pm_wakeup.h
> > @@ -107,7 +107,7 @@ extern void wakeup_sources_read_unlock(int idx);
> > extern struct wakeup_source *wakeup_sources_walk_start(void);
> > extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws);
> > extern int device_wakeup_enable(struct device *dev);
> > -extern int device_wakeup_disable(struct device *dev);
> > +extern void device_wakeup_disable(struct device *dev);
>
> This change will introduce a build error in sdhci-pci-core.c AFAICS,
> so you need to modify this file in the same patch to avoid bisection
> breakage.

Alright, I have respinned the series and fixed up the first patch
itself.

Thanks!


--
Best regards,
Dhruva Gole <[email protected]>