public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0077/1285] Replace numeric parameter like 0444 with macro
@ 2016-08-02 10:38 Baole Ni
  2016-08-02 12:42 ` Pavel Machek
  0 siblings, 1 reply; 3+ messages in thread
From: Baole Ni @ 2016-08-02 10:38 UTC (permalink / raw)
  To: rjw, len.brown, pavel, gregkh, hpa, x86
  Cc: linux-pm, linux-kernel, chuansheng.liu, baolex.ni

I find that the developers often just specified the numeric value
when calling a macro which is defined with a parameter for access permission.
As we know, these numeric value for access permission have had the corresponding macro,
and that using macro can improve the robustness and readability of the code,
thus, I suggest replacing the numeric parameter with the macro.

Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
Signed-off-by: Baole Ni <baolex.ni@intel.com>
---
 drivers/base/power/sysfs.c | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index a7b4679..8750805 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -125,7 +125,7 @@ static ssize_t control_store(struct device * dev, struct device_attribute *attr,
 	return n;
 }
 
-static DEVICE_ATTR(control, 0644, control_show, control_store);
+static DEVICE_ATTR(control, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, control_show, control_store);
 
 static ssize_t rtpm_active_time_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -138,7 +138,7 @@ static ssize_t rtpm_active_time_show(struct device *dev,
 	return ret;
 }
 
-static DEVICE_ATTR(runtime_active_time, 0444, rtpm_active_time_show, NULL);
+static DEVICE_ATTR(runtime_active_time, S_IRUSR | S_IRGRP | S_IROTH, rtpm_active_time_show, NULL);
 
 static ssize_t rtpm_suspended_time_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -152,7 +152,7 @@ static ssize_t rtpm_suspended_time_show(struct device *dev,
 	return ret;
 }
 
-static DEVICE_ATTR(runtime_suspended_time, 0444, rtpm_suspended_time_show, NULL);
+static DEVICE_ATTR(runtime_suspended_time, S_IRUSR | S_IRGRP | S_IROTH, rtpm_suspended_time_show, NULL);
 
 static ssize_t rtpm_status_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -184,7 +184,7 @@ static ssize_t rtpm_status_show(struct device *dev,
 	return sprintf(buf, p);
 }
 
-static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
+static DEVICE_ATTR(runtime_status, S_IRUSR | S_IRGRP | S_IROTH, rtpm_status_show, NULL);
 
 static ssize_t autosuspend_delay_ms_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
@@ -211,7 +211,7 @@ static ssize_t autosuspend_delay_ms_store(struct device *dev,
 	return n;
 }
 
-static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show,
+static DEVICE_ATTR(autosuspend_delay_ms, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, autosuspend_delay_ms_show,
 		autosuspend_delay_ms_store);
 
 static ssize_t pm_qos_resume_latency_show(struct device *dev,
@@ -239,7 +239,7 @@ static ssize_t pm_qos_resume_latency_store(struct device *dev,
 	return ret < 0 ? ret : n;
 }
 
-static DEVICE_ATTR(pm_qos_resume_latency_us, 0644,
+static DEVICE_ATTR(pm_qos_resume_latency_us, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
 		   pm_qos_resume_latency_show, pm_qos_resume_latency_store);
 
 static ssize_t pm_qos_latency_tolerance_show(struct device *dev,
@@ -273,7 +273,7 @@ static ssize_t pm_qos_latency_tolerance_store(struct device *dev,
 	return ret < 0 ? ret : n;
 }
 
-static DEVICE_ATTR(pm_qos_latency_tolerance_us, 0644,
+static DEVICE_ATTR(pm_qos_latency_tolerance_us, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
 		   pm_qos_latency_tolerance_show, pm_qos_latency_tolerance_store);
 
 static ssize_t pm_qos_no_power_off_show(struct device *dev,
@@ -300,7 +300,7 @@ static ssize_t pm_qos_no_power_off_store(struct device *dev,
 	return ret < 0 ? ret : n;
 }
 
-static DEVICE_ATTR(pm_qos_no_power_off, 0644,
+static DEVICE_ATTR(pm_qos_no_power_off, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
 		   pm_qos_no_power_off_show, pm_qos_no_power_off_store);
 
 static ssize_t pm_qos_remote_wakeup_show(struct device *dev,
@@ -327,7 +327,7 @@ static ssize_t pm_qos_remote_wakeup_store(struct device *dev,
 	return ret < 0 ? ret : n;
 }
 
-static DEVICE_ATTR(pm_qos_remote_wakeup, 0644,
+static DEVICE_ATTR(pm_qos_remote_wakeup, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH,
 		   pm_qos_remote_wakeup_show, pm_qos_remote_wakeup_store);
 
 #ifdef CONFIG_PM_SLEEP
@@ -366,7 +366,7 @@ wake_store(struct device * dev, struct device_attribute *attr,
 	return n;
 }
 
-static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
+static DEVICE_ATTR(wakeup, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, wake_show, wake_store);
 
 static ssize_t wakeup_count_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -383,7 +383,7 @@ static ssize_t wakeup_count_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_count, 0444, wakeup_count_show, NULL);
+static DEVICE_ATTR(wakeup_count, S_IRUSR | S_IRGRP | S_IROTH, wakeup_count_show, NULL);
 
 static ssize_t wakeup_active_count_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -400,7 +400,7 @@ static ssize_t wakeup_active_count_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_active_count, 0444, wakeup_active_count_show, NULL);
+static DEVICE_ATTR(wakeup_active_count, S_IRUSR | S_IRGRP | S_IROTH, wakeup_active_count_show, NULL);
 
 static ssize_t wakeup_abort_count_show(struct device *dev,
 					struct device_attribute *attr,
@@ -418,7 +418,7 @@ static ssize_t wakeup_abort_count_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_abort_count, 0444, wakeup_abort_count_show, NULL);
+static DEVICE_ATTR(wakeup_abort_count, S_IRUSR | S_IRGRP | S_IROTH, wakeup_abort_count_show, NULL);
 
 static ssize_t wakeup_expire_count_show(struct device *dev,
 					struct device_attribute *attr,
@@ -436,7 +436,7 @@ static ssize_t wakeup_expire_count_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_expire_count, 0444, wakeup_expire_count_show, NULL);
+static DEVICE_ATTR(wakeup_expire_count, S_IRUSR | S_IRGRP | S_IROTH, wakeup_expire_count_show, NULL);
 
 static ssize_t wakeup_active_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -453,7 +453,7 @@ static ssize_t wakeup_active_show(struct device *dev,
 	return enabled ? sprintf(buf, "%u\n", active) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_active, 0444, wakeup_active_show, NULL);
+static DEVICE_ATTR(wakeup_active, S_IRUSR | S_IRGRP | S_IROTH, wakeup_active_show, NULL);
 
 static ssize_t wakeup_total_time_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -470,7 +470,7 @@ static ssize_t wakeup_total_time_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_total_time_ms, 0444, wakeup_total_time_show, NULL);
+static DEVICE_ATTR(wakeup_total_time_ms, S_IRUSR | S_IRGRP | S_IROTH, wakeup_total_time_show, NULL);
 
 static ssize_t wakeup_max_time_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -487,7 +487,7 @@ static ssize_t wakeup_max_time_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_max_time_ms, 0444, wakeup_max_time_show, NULL);
+static DEVICE_ATTR(wakeup_max_time_ms, S_IRUSR | S_IRGRP | S_IROTH, wakeup_max_time_show, NULL);
 
 static ssize_t wakeup_last_time_show(struct device *dev,
 				struct device_attribute *attr, char *buf)
@@ -504,7 +504,7 @@ static ssize_t wakeup_last_time_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_last_time_ms, 0444, wakeup_last_time_show, NULL);
+static DEVICE_ATTR(wakeup_last_time_ms, S_IRUSR | S_IRGRP | S_IROTH, wakeup_last_time_show, NULL);
 
 #ifdef CONFIG_PM_AUTOSLEEP
 static ssize_t wakeup_prevent_sleep_time_show(struct device *dev,
@@ -523,7 +523,7 @@ static ssize_t wakeup_prevent_sleep_time_show(struct device *dev,
 	return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
 }
 
-static DEVICE_ATTR(wakeup_prevent_sleep_time_ms, 0444,
+static DEVICE_ATTR(wakeup_prevent_sleep_time_ms, S_IRUSR | S_IRGRP | S_IROTH,
 		   wakeup_prevent_sleep_time_show, NULL);
 #endif /* CONFIG_PM_AUTOSLEEP */
 #endif /* CONFIG_PM_SLEEP */
@@ -554,9 +554,9 @@ static ssize_t rtpm_enabled_show(struct device *dev,
 	return sprintf(buf, "enabled\n");
 }
 
-static DEVICE_ATTR(runtime_usage, 0444, rtpm_usagecount_show, NULL);
-static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show, NULL);
-static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL);
+static DEVICE_ATTR(runtime_usage, S_IRUSR | S_IRGRP | S_IROTH, rtpm_usagecount_show, NULL);
+static DEVICE_ATTR(runtime_active_kids, S_IRUSR | S_IRGRP | S_IROTH, rtpm_children_show, NULL);
+static DEVICE_ATTR(runtime_enabled, S_IRUSR | S_IRGRP | S_IROTH, rtpm_enabled_show, NULL);
 
 #ifdef CONFIG_PM_SLEEP
 static ssize_t async_show(struct device *dev, struct device_attribute *attr,
@@ -586,7 +586,7 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
 	return n;
 }
 
-static DEVICE_ATTR(async, 0644, async_show, async_store);
+static DEVICE_ATTR(async, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, async_show, async_store);
 
 #endif /* CONFIG_PM_SLEEP */
 #endif /* CONFIG_PM_ADVANCED_DEBUG */
-- 
2.9.2

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

* Re: [PATCH 0077/1285] Replace numeric parameter like 0444 with macro
  2016-08-02 10:38 [PATCH 0077/1285] Replace numeric parameter like 0444 with macro Baole Ni
@ 2016-08-02 12:42 ` Pavel Machek
  2016-08-03  7:29   ` Michal Kubecek
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Machek @ 2016-08-02 12:42 UTC (permalink / raw)
  To: Baole Ni
  Cc: rjw, len.brown, gregkh, hpa, x86, linux-pm, linux-kernel,
	chuansheng.liu

On Tue 2016-08-02 18:38:55, Baole Ni wrote:
> I find that the developers often just specified the numeric value
> when calling a macro which is defined with a parameter for access permission.
> As we know, these numeric value for access permission have had the corresponding macro,
> and that using macro can improve the robustness and readability of the code,
> thus, I suggest replacing the numeric parameter with the macro.
> 
> Signed-off-by: Chuansheng Liu <chuansheng.liu@intel.com>
> Signed-off-by: Baole Ni <baolex.ni@intel.com>

Sorry, the macros just make it _less_ readable, because you do chmod
666, not chmod S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH.

NAK.
							Pavel
							
> -static DEVICE_ATTR(control, 0644, control_show, control_store);
> +static DEVICE_ATTR(control, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, control_show, control_store);

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH 0077/1285] Replace numeric parameter like 0444 with macro
  2016-08-02 12:42 ` Pavel Machek
@ 2016-08-03  7:29   ` Michal Kubecek
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Kubecek @ 2016-08-03  7:29 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Baole Ni, rjw, len.brown, gregkh, hpa, x86, linux-pm,
	linux-kernel, chuansheng.liu

On Tue, Aug 02, 2016 at 02:42:56PM +0200, Pavel Machek wrote:
> 
> Sorry, the macros just make it _less_ readable, because you do chmod
> 666, not chmod S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH.

Actually, you can do "chmod a=rw ..." or "chmod u=rw,go=r ..." but very
few people use that syntax (the "+" or "-" variants come handy at times,
though).

                                                         Michal Kubecek

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

end of thread, other threads:[~2016-08-03  7:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-02 10:38 [PATCH 0077/1285] Replace numeric parameter like 0444 with macro Baole Ni
2016-08-02 12:42 ` Pavel Machek
2016-08-03  7:29   ` Michal Kubecek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox