summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorSami Kerola2016-07-24 23:33:01 +0200
committerSami Kerola2017-02-05 00:39:38 +0100
commitbd0786895d584644b47ef7e7ea923cda29e73fa6 (patch)
treecd07cca3ee59c6430bb93a1cf91bd8bc9063c422 /sys-utils
parenthwclock: remove division by zero [asan] (diff)
downloadkernel-qcow2-util-linux-bd0786895d584644b47ef7e7ea923cda29e73fa6.tar.gz
kernel-qcow2-util-linux-bd0786895d584644b47ef7e7ea923cda29e73fa6.tar.xz
kernel-qcow2-util-linux-bd0786895d584644b47ef7e7ea923cda29e73fa6.zip
hwclock: improve coding style
Make string constants to be symbolical declarations. Use longer variable name for rtc and cmos function pointer values. Exclude code that is architecture specific with preprocessor directives. And remove message duplication. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/hwclock-cmos.c19
-rw-r--r--sys-utils/hwclock-rtc.c18
2 files changed, 19 insertions, 18 deletions
diff --git a/sys-utils/hwclock-cmos.c b/sys-utils/hwclock-cmos.c
index 30f8765a5..284077eb8 100644
--- a/sys-utils/hwclock-cmos.c
+++ b/sys-utils/hwclock-cmos.c
@@ -54,6 +54,7 @@
#include "c.h"
#include "nls.h"
+#include "pathnames.h"
#if defined(__i386__) || defined(__x86_64__)
# ifdef HAVE_SYS_IO_H
@@ -154,12 +155,12 @@ static int is_in_cpuinfo(char *fmt, char *str)
{
FILE *cpuinfo;
char field[256];
- char format[256];
+ char format[sizeof(field)];
int found = 0;
sprintf(format, "%s : %s", fmt, "%255s");
- cpuinfo = fopen("/proc/cpuinfo", "r");
+ cpuinfo = fopen(_PATH_PROC_CPUINFO, "r");
if (cpuinfo) {
do {
if (fscanf(cpuinfo, format, field) == 1) {
@@ -525,9 +526,7 @@ static int read_hardware_clock_cmos(const struct hwclock_control *ctl
__attribute__((__unused__)), struct tm *tm)
{
bool got_time = FALSE;
- unsigned char status, pmbit;
-
- status = pmbit = 0; /* just for gcc */
+ unsigned char status = 0, pmbit = 0;
while (!got_time) {
/*
@@ -644,8 +643,8 @@ static int get_permissions_cmos(void)
int rc;
if (use_dev_port) {
- if ((dev_port_fd = open("/dev/port", O_RDWR)) < 0) {
- warn(_("cannot open %s"), "/dev/port");
+ if ((dev_port_fd = open(_PATH_DEV_PORT, O_RDWR)) < 0) {
+ warn(_("cannot open %s"), _PATH_DEV_PORT);
rc = 1;
} else
rc = 0;
@@ -664,7 +663,7 @@ static int get_permissions_cmos(void)
return rc ? 1 : 0;
}
-static struct clock_ops cmos = {
+static struct clock_ops cmos_interface = {
N_("Using direct I/O instructions to ISA clock."),
get_permissions_cmos,
read_hardware_clock_cmos,
@@ -678,11 +677,11 @@ static struct clock_ops cmos = {
*/
struct clock_ops *probe_for_cmos_clock(void)
{
- int have_cmos =
+ static const int have_cmos =
#if defined(__i386__) || defined(__alpha__) || defined(__x86_64__)
TRUE;
#else
FALSE;
#endif
- return have_cmos ? &cmos : NULL;
+ return have_cmos ? &cmos_interface : NULL;
}
diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c
index 5e11aeebd..f54e2633c 100644
--- a/sys-utils/hwclock-rtc.c
+++ b/sys-utils/hwclock-rtc.c
@@ -38,6 +38,7 @@
# include <asm/rtc.h>
#endif
*/
+#ifdef __sparc__
/* The following is roughly equivalent */
struct sparc_rtc_time
{
@@ -49,9 +50,9 @@ struct sparc_rtc_time
int month; /* Month of year 1-12 */
int year; /* Year 0-99 */
};
-
#define RTCGET _IOR('p', 20, struct sparc_rtc_time)
#define RTCSET _IOW('p', 21, struct sparc_rtc_time)
+#endif
/*
* struct rtc_time is present since 1.3.99.
@@ -374,7 +375,7 @@ static int get_permissions_rtc(void)
return 0;
}
-static struct clock_ops rtc = {
+static struct clock_ops rtc_interface = {
N_("Using the rtc interface to the clock."),
get_permissions_rtc,
read_hardware_clock_rtc,
@@ -385,14 +386,14 @@ static struct clock_ops rtc = {
/* return &rtc if /dev/rtc can be opened, NULL otherwise */
struct clock_ops *probe_for_rtc_clock(const struct hwclock_control *ctl)
{
- int rtc_fd = open_rtc(ctl);
- if (rtc_fd >= 0)
- return &rtc;
- if (ctl->debug)
- warn(_("cannot open rtc device"));
- return NULL;
+ const int rtc_fd = open_rtc(ctl);
+
+ if (rtc_fd < 0)
+ return NULL;
+ return &rtc_interface;
}
+#ifdef __alpha__
/*
* Get the Hardware Clock epoch setting from the kernel.
*/
@@ -478,3 +479,4 @@ int set_epoch_rtc(const struct hwclock_control *ctl)
return 0;
}
+#endif /* __alpha__ */