2007-11-07 10:28:39

by Daniel Drake

[permalink] [raw]
Subject: [PATCH] create /sys/.../power when CONFIG_PM is set

The CONFIG_SUSPEND changes in 2.6.23 caused a regression under certain
configuration conditions (SUSPEND=n, USB_AUTOSUSPEND=y) where all USB device
attributes in sysfs (idVendor, idProduct, ...) silently disappeared, causing
udev breakage and more.

The cause of this is that the /sys/.../power subdirectory is now only created
when CONFIG_PM_SLEEP is set, however, it should be created whenever CONFIG_PM
is set to handle the above situation. The following patch fixes the
regression.

Signed-off-by: Daniel Drake <[email protected]>

Index: linux-2.6.24-rc1-git14/drivers/base/core.c
===================================================================
--- linux-2.6.24-rc1-git14.orig/drivers/base/core.c
+++ linux-2.6.24-rc1-git14/drivers/base/core.c
@@ -770,9 +770,10 @@ int device_add(struct device *dev)
error = device_add_attrs(dev);
if (error)
goto AttrsError;
- error = device_pm_add(dev);
+ error = dpm_sysfs_add(dev);
if (error)
goto PMError;
+ device_pm_add(dev);
error = bus_add_device(dev);
if (error)
goto BusError;
@@ -797,6 +798,7 @@ int device_add(struct device *dev)
return error;
BusError:
device_pm_remove(dev);
+ dpm_sysfs_remove(dev);
PMError:
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->bus_notifier,
Index: linux-2.6.24-rc1-git14/drivers/base/power/Makefile
===================================================================
--- linux-2.6.24-rc1-git14.orig/drivers/base/power/Makefile
+++ linux-2.6.24-rc1-git14/drivers/base/power/Makefile
@@ -1,5 +1,6 @@
obj-y := shutdown.o
-obj-$(CONFIG_PM_SLEEP) += main.o sysfs.o
+obj-$(CONFIG_PM) += sysfs.o
+obj-$(CONFIG_PM_SLEEP) += main.o
obj-$(CONFIG_PM_TRACE) += trace.o

ifeq ($(CONFIG_DEBUG_DRIVER),y)
Index: linux-2.6.24-rc1-git14/drivers/base/power/power.h
===================================================================
--- linux-2.6.24-rc1-git14.orig/drivers/base/power/power.h
+++ linux-2.6.24-rc1-git14/drivers/base/power/power.h
@@ -18,9 +18,24 @@ static inline struct device * to_device(
return container_of(entry, struct device, power.entry);
}

-extern int device_pm_add(struct device *);
+extern void device_pm_add(struct device *);
extern void device_pm_remove(struct device *);

+#else /* CONFIG_PM_SLEEP */
+
+
+static inline void device_pm_add(struct device * dev)
+{
+}
+static inline void device_pm_remove(struct device * dev)
+{
+
+}
+
+#endif
+
+#ifdef CONFIG_PM
+
/*
* sysfs.c
*/
@@ -28,16 +43,16 @@ extern void device_pm_remove(struct devi
extern int dpm_sysfs_add(struct device *);
extern void dpm_sysfs_remove(struct device *);

-#else /* CONFIG_PM_SLEEP */
+#else /* CONFIG_PM */

-
-static inline int device_pm_add(struct device * dev)
+static inline int dpm_sysfs_add(struct device * dev)
{
return 0;
}
-static inline void device_pm_remove(struct device * dev)
+static inline void dpm_sysfs_remove(struct device * dev)
{

}

-#endif
+#endif /* CONFIG_PM */
+
Index: linux-2.6.24-rc1-git14/drivers/base/power/main.c
===================================================================
--- linux-2.6.24-rc1-git14.orig/drivers/base/power/main.c
+++ linux-2.6.24-rc1-git14/drivers/base/power/main.c
@@ -38,20 +38,14 @@ static DEFINE_MUTEX(dpm_list_mtx);
int (*platform_enable_wakeup)(struct device *dev, int is_on);


-int device_pm_add(struct device *dev)
+void device_pm_add(struct device *dev)
{
- int error;
-
pr_debug("PM: Adding info for %s:%s\n",
dev->bus ? dev->bus->name : "No Bus",
kobject_name(&dev->kobj));
mutex_lock(&dpm_list_mtx);
list_add_tail(&dev->power.entry, &dpm_active);
- error = dpm_sysfs_add(dev);
- if (error)
- list_del(&dev->power.entry);
mutex_unlock(&dpm_list_mtx);
- return error;
}

void device_pm_remove(struct device *dev)


2007-11-07 16:45:25

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH] create /sys/.../power when CONFIG_PM is set

On Wed, 7 Nov 2007, Daniel Drake wrote:

> The CONFIG_SUSPEND changes in 2.6.23 caused a regression under certain
> configuration conditions (SUSPEND=n, USB_AUTOSUSPEND=y) where all USB device
> attributes in sysfs (idVendor, idProduct, ...) silently disappeared, causing
> udev breakage and more.
>
> The cause of this is that the /sys/.../power subdirectory is now only created
> when CONFIG_PM_SLEEP is set, however, it should be created whenever CONFIG_PM
> is set to handle the above situation. The following patch fixes the
> regression.
>
> Signed-off-by: Daniel Drake <[email protected]>

I haven't tried applying this, but it looks okay to me. There may be
some conflict with other changes already merged in the PM core.

Alan Stern

2007-11-07 22:07:46

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] create /sys/.../power when CONFIG_PM is set

On Wednesday, 7 of November 2007, Daniel Drake wrote:
> The CONFIG_SUSPEND changes in 2.6.23 caused a regression under certain
> configuration conditions (SUSPEND=n, USB_AUTOSUSPEND=y) where all USB device
> attributes in sysfs (idVendor, idProduct, ...) silently disappeared, causing
> udev breakage and more.
>
> The cause of this is that the /sys/.../power subdirectory is now only created
> when CONFIG_PM_SLEEP is set, however, it should be created whenever CONFIG_PM
> is set to handle the above situation. The following patch fixes the
> regression.
>
> Signed-off-by: Daniel Drake <[email protected]>

Acked-by: Rafael J. Wysocki <[email protected]>

Greg, I think this patch should go through your tree?

> Index: linux-2.6.24-rc1-git14/drivers/base/core.c
> ===================================================================
> --- linux-2.6.24-rc1-git14.orig/drivers/base/core.c
> +++ linux-2.6.24-rc1-git14/drivers/base/core.c
> @@ -770,9 +770,10 @@ int device_add(struct device *dev)
> error = device_add_attrs(dev);
> if (error)
> goto AttrsError;
> - error = device_pm_add(dev);
> + error = dpm_sysfs_add(dev);
> if (error)
> goto PMError;
> + device_pm_add(dev);
> error = bus_add_device(dev);
> if (error)
> goto BusError;
> @@ -797,6 +798,7 @@ int device_add(struct device *dev)
> return error;
> BusError:
> device_pm_remove(dev);
> + dpm_sysfs_remove(dev);
> PMError:
> if (dev->bus)
> blocking_notifier_call_chain(&dev->bus->bus_notifier,
> Index: linux-2.6.24-rc1-git14/drivers/base/power/Makefile
> ===================================================================
> --- linux-2.6.24-rc1-git14.orig/drivers/base/power/Makefile
> +++ linux-2.6.24-rc1-git14/drivers/base/power/Makefile
> @@ -1,5 +1,6 @@
> obj-y := shutdown.o
> -obj-$(CONFIG_PM_SLEEP) += main.o sysfs.o
> +obj-$(CONFIG_PM) += sysfs.o
> +obj-$(CONFIG_PM_SLEEP) += main.o
> obj-$(CONFIG_PM_TRACE) += trace.o
>
> ifeq ($(CONFIG_DEBUG_DRIVER),y)
> Index: linux-2.6.24-rc1-git14/drivers/base/power/power.h
> ===================================================================
> --- linux-2.6.24-rc1-git14.orig/drivers/base/power/power.h
> +++ linux-2.6.24-rc1-git14/drivers/base/power/power.h
> @@ -18,9 +18,24 @@ static inline struct device * to_device(
> return container_of(entry, struct device, power.entry);
> }
>
> -extern int device_pm_add(struct device *);
> +extern void device_pm_add(struct device *);
> extern void device_pm_remove(struct device *);
>
> +#else /* CONFIG_PM_SLEEP */
> +
> +
> +static inline void device_pm_add(struct device * dev)
> +{
> +}
> +static inline void device_pm_remove(struct device * dev)
> +{
> +
> +}
> +
> +#endif
> +
> +#ifdef CONFIG_PM
> +
> /*
> * sysfs.c
> */
> @@ -28,16 +43,16 @@ extern void device_pm_remove(struct devi
> extern int dpm_sysfs_add(struct device *);
> extern void dpm_sysfs_remove(struct device *);
>
> -#else /* CONFIG_PM_SLEEP */
> +#else /* CONFIG_PM */
>
> -
> -static inline int device_pm_add(struct device * dev)
> +static inline int dpm_sysfs_add(struct device * dev)
> {
> return 0;
> }
> -static inline void device_pm_remove(struct device * dev)
> +static inline void dpm_sysfs_remove(struct device * dev)
> {
>
> }
>
> -#endif
> +#endif /* CONFIG_PM */
> +
> Index: linux-2.6.24-rc1-git14/drivers/base/power/main.c
> ===================================================================
> --- linux-2.6.24-rc1-git14.orig/drivers/base/power/main.c
> +++ linux-2.6.24-rc1-git14/drivers/base/power/main.c
> @@ -38,20 +38,14 @@ static DEFINE_MUTEX(dpm_list_mtx);
> int (*platform_enable_wakeup)(struct device *dev, int is_on);
>
>
> -int device_pm_add(struct device *dev)
> +void device_pm_add(struct device *dev)
> {
> - int error;
> -
> pr_debug("PM: Adding info for %s:%s\n",
> dev->bus ? dev->bus->name : "No Bus",
> kobject_name(&dev->kobj));
> mutex_lock(&dpm_list_mtx);
> list_add_tail(&dev->power.entry, &dpm_active);
> - error = dpm_sysfs_add(dev);
> - if (error)
> - list_del(&dev->power.entry);
> mutex_unlock(&dpm_list_mtx);
> - return error;
> }
>
> void device_pm_remove(struct device *dev)
>
>

2007-11-08 00:32:21

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] create /sys/.../power when CONFIG_PM is set

On Wed, Nov 07, 2007 at 11:24:55PM +0100, Rafael J. Wysocki wrote:
> On Wednesday, 7 of November 2007, Daniel Drake wrote:
> > The CONFIG_SUSPEND changes in 2.6.23 caused a regression under certain
> > configuration conditions (SUSPEND=n, USB_AUTOSUSPEND=y) where all USB device
> > attributes in sysfs (idVendor, idProduct, ...) silently disappeared, causing
> > udev breakage and more.
> >
> > The cause of this is that the /sys/.../power subdirectory is now only created
> > when CONFIG_PM_SLEEP is set, however, it should be created whenever CONFIG_PM
> > is set to handle the above situation. The following patch fixes the
> > regression.
> >
> > Signed-off-by: Daniel Drake <[email protected]>
>
> Acked-by: Rafael J. Wysocki <[email protected]>
>
> Greg, I think this patch should go through your tree?

Yes, I'll take it. I'm at a conference until Friday, but will take it
then and then get it to Linus before 2.6.24 is out.

thanks,

greg k-h

2007-11-09 21:06:35

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] create /sys/.../power when CONFIG_PM is set

On Wed, 7 Nov 2007 10:10:43 +0000 (GMT)
Daniel Drake <[email protected]> wrote:

> The CONFIG_SUSPEND changes in 2.6.23 caused a regression under certain
> configuration conditions (SUSPEND=n, USB_AUTOSUSPEND=y) where all USB device
> attributes in sysfs (idVendor, idProduct, ...) silently disappeared, causing
> udev breakage and more.
>
> The cause of this is that the /sys/.../power subdirectory is now only created
> when CONFIG_PM_SLEEP is set, however, it should be created whenever CONFIG_PM
> is set to handle the above situation. The following patch fixes the
> regression.
>

Your patch is for 2.6.24-rc2 and 2.6.23, afacit. It needed some work to
apply on Greg's tree because the new pm_sleep_lock() and pm_sleep_unlock()
went and copied the same bug as you've fixed here.

I guess the right thing to do is to apply your patch as-is to 2.6.24-rcX
and to 2.6.23.x. I can't really do that because doing so would wreck my
copy of Greg's tree.


So I'll run with the below (I think it's right) and will let Greg sort it
out ;)



From: Daniel Drake <[email protected]>

The CONFIG_SUSPEND changes in 2.6.23 caused a regression under certain
configuration conditions (SUSPEND=n, USB_AUTOSUSPEND=y) where all USB
device attributes in sysfs (idVendor, idProduct, ...) silently disappeared,
causing udev breakage and more.

The cause of this is that the /sys/.../power subdirectory is now only
created when CONFIG_PM_SLEEP is set, however, it should be created whenever
CONFIG_PM is set to handle the above situation. The following patch fixes
the regression.

Signed-off-by: Daniel Drake <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Cc: Alan Stern <[email protected]>
Cc: Greg KH <[email protected]>
Cc: Kay Sievers <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---

drivers/base/core.c | 4 ++-
drivers/base/power/Makefile | 3 +-
drivers/base/power/main.c | 8 ------
drivers/base/power/power.h | 40 ++++++++++++++++++++++------------
4 files changed, 33 insertions(+), 22 deletions(-)

diff -puN drivers/base/core.c~create-sys-power-when-config_pm-is-set drivers/base/core.c
--- a/drivers/base/core.c~create-sys-power-when-config_pm-is-set
+++ a/drivers/base/core.c
@@ -785,9 +785,10 @@ int device_add(struct device *dev)
error = device_add_attrs(dev);
if (error)
goto AttrsError;
- error = device_pm_add(dev);
+ error = dpm_sysfs_add(dev);
if (error)
goto PMError;
+ device_pm_add(dev);
error = bus_add_device(dev);
if (error)
goto BusError;
@@ -813,6 +814,7 @@ int device_add(struct device *dev)
return error;
BusError:
device_pm_remove(dev);
+ dpm_sysfs_remove(dev);
PMError:
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
diff -puN drivers/base/power/Makefile~create-sys-power-when-config_pm-is-set drivers/base/power/Makefile
--- a/drivers/base/power/Makefile~create-sys-power-when-config_pm-is-set
+++ a/drivers/base/power/Makefile
@@ -1,5 +1,6 @@
obj-y := shutdown.o
-obj-$(CONFIG_PM_SLEEP) += main.o sysfs.o
+obj-$(CONFIG_PM) += sysfs.o
+obj-$(CONFIG_PM_SLEEP) += main.o
obj-$(CONFIG_PM_TRACE) += trace.o

ifeq ($(CONFIG_DEBUG_DRIVER),y)
diff -puN drivers/base/power/main.c~create-sys-power-when-config_pm-is-set drivers/base/power/main.c
--- a/drivers/base/power/main.c~create-sys-power-when-config_pm-is-set
+++ a/drivers/base/power/main.c
@@ -59,20 +59,14 @@ static DECLARE_RWSEM(pm_sleep_rwsem);
int (*platform_enable_wakeup)(struct device *dev, int is_on);


-int device_pm_add(struct device *dev)
+void device_pm_add(struct device *dev)
{
- int error;
-
pr_debug("PM: Adding info for %s:%s\n",
dev->bus ? dev->bus->name : "No Bus",
kobject_name(&dev->kobj));
mutex_lock(&dpm_list_mtx);
list_add_tail(&dev->power.entry, &dpm_active);
- error = dpm_sysfs_add(dev);
- if (error)
- list_del(&dev->power.entry);
mutex_unlock(&dpm_list_mtx);
- return error;
}

void device_pm_remove(struct device *dev)
diff -puN drivers/base/power/power.h~create-sys-power-when-config_pm-is-set drivers/base/power/power.h
--- a/drivers/base/power/power.h~create-sys-power-when-config_pm-is-set
+++ a/drivers/base/power/power.h
@@ -13,31 +13,23 @@ extern void device_shutdown(void);

extern struct list_head dpm_active; /* The active device list */

-static inline struct device * to_device(struct list_head * entry)
+static inline struct device *to_device(struct list_head *entry)
{
return container_of(entry, struct device, power.entry);
}

-extern int device_pm_add(struct device *);
+extern void device_pm_add(struct device *);
extern void device_pm_remove(struct device *);
extern int pm_sleep_lock(void);
extern void pm_sleep_unlock(void);

-/*
- * sysfs.c
- */
-
-extern int dpm_sysfs_add(struct device *);
-extern void dpm_sysfs_remove(struct device *);
-
#else /* CONFIG_PM_SLEEP */

-
-static inline int device_pm_add(struct device * dev)
+static inline void device_pm_add(struct device *dev)
{
- return 0;
}
-static inline void device_pm_remove(struct device * dev)
+
+static inline void device_pm_remove(struct device *dev)
{
}

@@ -51,3 +43,25 @@ static inline void pm_sleep_unlock(void)
}

#endif
+
+#ifdef CONFIG_PM
+
+/*
+ * sysfs.c
+ */
+
+extern int dpm_sysfs_add(struct device *);
+extern void dpm_sysfs_remove(struct device *);
+
+#else /* CONFIG_PM */
+
+static inline int dpm_sysfs_add(struct device *dev)
+{
+ return 0;
+}
+
+static inline void dpm_sysfs_remove(struct device *dev)
+{
+}
+
+#endif
_

2007-11-09 22:09:06

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH] create /sys/.../power when CONFIG_PM is set

On Fri, Nov 09, 2007 at 01:05:55PM -0800, Andrew Morton wrote:
> On Wed, 7 Nov 2007 10:10:43 +0000 (GMT)
> Daniel Drake <[email protected]> wrote:
>
> > The CONFIG_SUSPEND changes in 2.6.23 caused a regression under certain
> > configuration conditions (SUSPEND=n, USB_AUTOSUSPEND=y) where all USB device
> > attributes in sysfs (idVendor, idProduct, ...) silently disappeared, causing
> > udev breakage and more.
> >
> > The cause of this is that the /sys/.../power subdirectory is now only created
> > when CONFIG_PM_SLEEP is set, however, it should be created whenever CONFIG_PM
> > is set to handle the above situation. The following patch fixes the
> > regression.
> >
>
> Your patch is for 2.6.24-rc2 and 2.6.23, afacit. It needed some work to
> apply on Greg's tree because the new pm_sleep_lock() and pm_sleep_unlock()
> went and copied the same bug as you've fixed here.
>
> I guess the right thing to do is to apply your patch as-is to 2.6.24-rcX
> and to 2.6.23.x. I can't really do that because doing so would wreck my
> copy of Greg's tree.
>
>
> So I'll run with the below (I think it's right) and will let Greg sort it
> out ;)

Yeah, I'll sort it all out :)

thanks,

greg k-h