linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean
@ 2015-07-23 23:01 Dmitry Torokhov
  2015-07-23 23:01 ` [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW Dmitry Torokhov
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2015-07-23 23:01 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Alessandro Zummo, rtc-linux, linux-kernel, Krzysztof Kozlowski

Users of rtc_does_wakealarm() return value treat it as boolean so let's
change the signature accordingly.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/rtc/rtc-sysfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index babd43b..2fbc11b 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -230,10 +230,11 @@ static DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
  * suspend-to-disk.  So: no attribute unless that side effect is possible.
  * (Userspace may disable that mechanism later.)
  */
-static inline int rtc_does_wakealarm(struct rtc_device *rtc)
+static bool rtc_does_wakealarm(struct rtc_device *rtc)
 {
 	if (!device_can_wakeup(rtc->dev.parent))
-		return 0;
+		return false;
+
 	return rtc->ops->set_alarm != NULL;
 }
 
-- 
2.5.0.rc2.392.g76e840b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW
  2015-07-23 23:01 [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Dmitry Torokhov
@ 2015-07-23 23:01 ` Dmitry Torokhov
  2015-07-24  4:08   ` Krzysztof Kozlowski
  2015-08-05  1:40   ` Alexandre Belloni
  2015-07-23 23:01 ` [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes Dmitry Torokhov
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2015-07-23 23:01 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Alessandro Zummo, rtc-linux, linux-kernel, Krzysztof Kozlowski

Instead of using older style DEVICE_ATTR for wakealarm attribute let's
switch to using DEVICE_ATTR_RW that ensures consistent across the kernel
permissions on the attribute.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/rtc/rtc-sysfs.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 2fbc11b..e3ce1dc 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -134,8 +134,7 @@ static struct attribute *rtc_attrs[] = {
 ATTRIBUTE_GROUPS(rtc);
 
 static ssize_t
-rtc_sysfs_show_wakealarm(struct device *dev, struct device_attribute *attr,
-		char *buf)
+wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	ssize_t retval;
 	unsigned long alarm;
@@ -159,7 +158,7 @@ rtc_sysfs_show_wakealarm(struct device *dev, struct device_attribute *attr,
 }
 
 static ssize_t
-rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
+wakealarm_store(struct device *dev, struct device_attribute *attr,
 		const char *buf, size_t n)
 {
 	ssize_t retval;
@@ -221,8 +220,7 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
 	retval = rtc_set_alarm(rtc, &alm);
 	return (retval < 0) ? retval : n;
 }
-static DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
-		rtc_sysfs_show_wakealarm, rtc_sysfs_set_wakealarm);
+static DEVICE_ATTR_RW(wakealarm);
 
 
 /* The reason to trigger an alarm with no process watching it (via sysfs)
-- 
2.5.0.rc2.392.g76e840b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes
  2015-07-23 23:01 [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Dmitry Torokhov
  2015-07-23 23:01 ` [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW Dmitry Torokhov
@ 2015-07-23 23:01 ` Dmitry Torokhov
  2015-07-24  4:10   ` Krzysztof Kozlowski
  2015-08-05  1:41   ` Alexandre Belloni
  2015-07-24  4:10 ` [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Krzysztof Kozlowski
  2015-08-05  1:40 ` Alexandre Belloni
  3 siblings, 2 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2015-07-23 23:01 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Alessandro Zummo, rtc-linux, linux-kernel, Krzysztof Kozlowski

Instead of creating wakealarm attribute manually, after the device has been
registered, let's rely on facilities provided by the attribute groups to
control which attributes are visible and which are not. This allows to to
create all needed attributes at once, at the same time that we register RTC
class device.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/rtc/class.c     |  4 +---
 drivers/rtc/rtc-core.h  | 19 +++-------------
 drivers/rtc/rtc-sysfs.c | 59 +++++++++++++++++++++++++------------------------
 3 files changed, 34 insertions(+), 48 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index de7707f..de86578 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -202,6 +202,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
 	rtc->max_user_freq = 64;
 	rtc->dev.parent = dev;
 	rtc->dev.class = rtc_class;
+	rtc->dev.groups = rtc_get_dev_attribute_groups();
 	rtc->dev.release = rtc_device_release;
 
 	mutex_init(&rtc->ops_lock);
@@ -240,7 +241,6 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
 	}
 
 	rtc_dev_add_device(rtc);
-	rtc_sysfs_add_device(rtc);
 	rtc_proc_add_device(rtc);
 
 	dev_info(dev, "rtc core: registered %s as %s\n",
@@ -271,7 +271,6 @@ void rtc_device_unregister(struct rtc_device *rtc)
 	 * Remove innards of this RTC, then disable it, before
 	 * letting any rtc_class_open() users access it again
 	 */
-	rtc_sysfs_del_device(rtc);
 	rtc_dev_del_device(rtc);
 	rtc_proc_del_device(rtc);
 	device_del(&rtc->dev);
@@ -360,7 +359,6 @@ static int __init rtc_init(void)
 	}
 	rtc_class->pm = RTC_CLASS_DEV_PM_OPS;
 	rtc_dev_init();
-	rtc_sysfs_init(rtc_class);
 	return 0;
 }
 
diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h
index 5f9df74..a098aea 100644
--- a/drivers/rtc/rtc-core.h
+++ b/drivers/rtc/rtc-core.h
@@ -48,23 +48,10 @@ static inline void rtc_proc_del_device(struct rtc_device *rtc)
 #endif
 
 #ifdef CONFIG_RTC_INTF_SYSFS
-
-extern void __init rtc_sysfs_init(struct class *);
-extern void rtc_sysfs_add_device(struct rtc_device *rtc);
-extern void rtc_sysfs_del_device(struct rtc_device *rtc);
-
+const struct attribute_group **rtc_get_dev_attribute_groups(void);
 #else
-
-static inline void rtc_sysfs_init(struct class *rtc)
-{
-}
-
-static inline void rtc_sysfs_add_device(struct rtc_device *rtc)
+static inline const struct attribute_group **rtc_get_dev_attribute_groups(void)
 {
+	return NULL;
 }
-
-static inline void rtc_sysfs_del_device(struct rtc_device *rtc)
-{
-}
-
 #endif
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index e3ce1dc..7273855 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -122,17 +122,6 @@ hctosys_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR_RO(hctosys);
 
-static struct attribute *rtc_attrs[] = {
-	&dev_attr_name.attr,
-	&dev_attr_date.attr,
-	&dev_attr_time.attr,
-	&dev_attr_since_epoch.attr,
-	&dev_attr_max_user_freq.attr,
-	&dev_attr_hctosys.attr,
-	NULL,
-};
-ATTRIBUTE_GROUPS(rtc);
-
 static ssize_t
 wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -222,6 +211,16 @@ wakealarm_store(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RW(wakealarm);
 
+static struct attribute *rtc_attrs[] = {
+	&dev_attr_name.attr,
+	&dev_attr_date.attr,
+	&dev_attr_time.attr,
+	&dev_attr_since_epoch.attr,
+	&dev_attr_max_user_freq.attr,
+	&dev_attr_hctosys.attr,
+	&dev_attr_wakealarm.attr,
+	NULL,
+};
 
 /* The reason to trigger an alarm with no process watching it (via sysfs)
  * is its side effect:  waking from a system state like suspend-to-RAM or
@@ -236,29 +235,31 @@ static bool rtc_does_wakealarm(struct rtc_device *rtc)
 	return rtc->ops->set_alarm != NULL;
 }
 
-
-void rtc_sysfs_add_device(struct rtc_device *rtc)
+static umode_t rtc_attr_is_visible(struct kobject *kobj,
+				   struct attribute *attr, int n)
 {
-	int err;
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct rtc_device *rtc = to_rtc_device(dev);
+	umode_t mode = attr->mode;
 
-	/* not all RTCs support both alarms and wakeup */
-	if (!rtc_does_wakealarm(rtc))
-		return;
+	if (attr == &dev_attr_wakealarm.attr)
+		if (!rtc_does_wakealarm(rtc))
+			mode = 0;
 
-	err = device_create_file(&rtc->dev, &dev_attr_wakealarm);
-	if (err)
-		dev_err(rtc->dev.parent,
-			"failed to create alarm attribute, %d\n", err);
+	return mode;
 }
 
-void rtc_sysfs_del_device(struct rtc_device *rtc)
-{
-	/* REVISIT did we add it successfully? */
-	if (rtc_does_wakealarm(rtc))
-		device_remove_file(&rtc->dev, &dev_attr_wakealarm);
-}
+static struct attribute_group rtc_attr_group = {
+	.is_visible	= rtc_attr_is_visible,
+	.attrs		= rtc_attrs,
+};
+
+static const struct attribute_group *rtc_attr_groups[] = {
+	&rtc_attr_group,
+	NULL
+};
 
-void __init rtc_sysfs_init(struct class *rtc_class)
+const struct attribute_group **rtc_get_dev_attribute_groups(void)
 {
-	rtc_class->dev_groups = rtc_groups;
+	return rtc_attr_groups;
 }
-- 
2.5.0.rc2.392.g76e840b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW
  2015-07-23 23:01 ` [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW Dmitry Torokhov
@ 2015-07-24  4:08   ` Krzysztof Kozlowski
  2015-08-05  1:40   ` Alexandre Belloni
  1 sibling, 0 replies; 9+ messages in thread
From: Krzysztof Kozlowski @ 2015-07-24  4:08 UTC (permalink / raw)
  To: Dmitry Torokhov, Alexandre Belloni
  Cc: Alessandro Zummo, rtc-linux, linux-kernel

On 24.07.2015 08:01, Dmitry Torokhov wrote:
> Instead of using older style DEVICE_ATTR for wakealarm attribute let's
> switch to using DEVICE_ATTR_RW that ensures consistent across the kernel
> permissions on the attribute.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/rtc/rtc-sysfs.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes
  2015-07-23 23:01 ` [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes Dmitry Torokhov
@ 2015-07-24  4:10   ` Krzysztof Kozlowski
  2015-08-05  1:41   ` Alexandre Belloni
  1 sibling, 0 replies; 9+ messages in thread
From: Krzysztof Kozlowski @ 2015-07-24  4:10 UTC (permalink / raw)
  To: Dmitry Torokhov, Alexandre Belloni
  Cc: Alessandro Zummo, rtc-linux, linux-kernel

On 24.07.2015 08:01, Dmitry Torokhov wrote:
> Instead of creating wakealarm attribute manually, after the device has been
> registered, let's rely on facilities provided by the attribute groups to
> control which attributes are visible and which are not. This allows to to
> create all needed attributes at once, at the same time that we register RTC
> class device.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/rtc/class.c     |  4 +---
>  drivers/rtc/rtc-core.h  | 19 +++-------------
>  drivers/rtc/rtc-sysfs.c | 59 +++++++++++++++++++++++++------------------------
>  3 files changed, 34 insertions(+), 48 deletions(-)

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean
  2015-07-23 23:01 [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Dmitry Torokhov
  2015-07-23 23:01 ` [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW Dmitry Torokhov
  2015-07-23 23:01 ` [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes Dmitry Torokhov
@ 2015-07-24  4:10 ` Krzysztof Kozlowski
  2015-08-05  1:40 ` Alexandre Belloni
  3 siblings, 0 replies; 9+ messages in thread
From: Krzysztof Kozlowski @ 2015-07-24  4:10 UTC (permalink / raw)
  To: Dmitry Torokhov, Alexandre Belloni
  Cc: Alessandro Zummo, rtc-linux, linux-kernel

On 24.07.2015 08:01, Dmitry Torokhov wrote:
> Users of rtc_does_wakealarm() return value treat it as boolean so let's
> change the signature accordingly.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/rtc/rtc-sysfs.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Thanks for splitting this.

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean
  2015-07-23 23:01 [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Dmitry Torokhov
                   ` (2 preceding siblings ...)
  2015-07-24  4:10 ` [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Krzysztof Kozlowski
@ 2015-08-05  1:40 ` Alexandre Belloni
  3 siblings, 0 replies; 9+ messages in thread
From: Alexandre Belloni @ 2015-08-05  1:40 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Alessandro Zummo, rtc-linux, linux-kernel, Krzysztof Kozlowski

On 23/07/2015 at 16:01:06 -0700, Dmitry Torokhov wrote :
> Users of rtc_does_wakealarm() return value treat it as boolean so let's
> change the signature accordingly.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Applied, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW
  2015-07-23 23:01 ` [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW Dmitry Torokhov
  2015-07-24  4:08   ` Krzysztof Kozlowski
@ 2015-08-05  1:40   ` Alexandre Belloni
  1 sibling, 0 replies; 9+ messages in thread
From: Alexandre Belloni @ 2015-08-05  1:40 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Alessandro Zummo, rtc-linux, linux-kernel, Krzysztof Kozlowski

On 23/07/2015 at 16:01:07 -0700, Dmitry Torokhov wrote :
> Instead of using older style DEVICE_ATTR for wakealarm attribute let's
> switch to using DEVICE_ATTR_RW that ensures consistent across the kernel
> permissions on the attribute.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Applied, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes
  2015-07-23 23:01 ` [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes Dmitry Torokhov
  2015-07-24  4:10   ` Krzysztof Kozlowski
@ 2015-08-05  1:41   ` Alexandre Belloni
  1 sibling, 0 replies; 9+ messages in thread
From: Alexandre Belloni @ 2015-08-05  1:41 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Alessandro Zummo, rtc-linux, linux-kernel, Krzysztof Kozlowski

On 23/07/2015 at 16:01:08 -0700, Dmitry Torokhov wrote :
> Instead of creating wakealarm attribute manually, after the device has been
> registered, let's rely on facilities provided by the attribute groups to
> control which attributes are visible and which are not. This allows to to
> create all needed attributes at once, at the same time that we register RTC
> class device.
> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Applied, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-08-05  1:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-23 23:01 [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Dmitry Torokhov
2015-07-23 23:01 ` [PATCH v2 2/3] RTC: switch wakealarm attribute to DEVICE_ATTR_RW Dmitry Torokhov
2015-07-24  4:08   ` Krzysztof Kozlowski
2015-08-05  1:40   ` Alexandre Belloni
2015-07-23 23:01 ` [PATCH v2 3/3] RTC: switch to using is_visible() to control sysfs attributes Dmitry Torokhov
2015-07-24  4:10   ` Krzysztof Kozlowski
2015-08-05  1:41   ` Alexandre Belloni
2015-07-24  4:10 ` [PATCH v2 1/3] RTC: make rtc_does_wakealarm() return boolean Krzysztof Kozlowski
2015-08-05  1:40 ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).