2015-11-25 13:43:36

by Corentin Labbe

[permalink] [raw]
Subject: [PATCH 1/4] ipmi: constify the name parameter of ipmi_smi_add_proc_entry

The name parameter of ipmi_smi_add_proc_entry() is never modified.
Furthermore, the name parameter of ipmi_smi_add_proc_entry is always given
string literal.

Signed-off-by: LABBE Corentin <[email protected]>
---
drivers/char/ipmi/ipmi_msghandler.c | 2 +-
include/linux/ipmi_smi.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 94fb407..ff64600 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -2121,7 +2121,7 @@ static const struct file_operations smi_stats_proc_ops = {
};
#endif /* CONFIG_PROC_FS */

-int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
+int ipmi_smi_add_proc_entry(ipmi_smi_t smi, const char *name,
const struct file_operations *proc_ops,
void *data)
{
diff --git a/include/linux/ipmi_smi.h b/include/linux/ipmi_smi.h
index f8cea14..4ceabae 100644
--- a/include/linux/ipmi_smi.h
+++ b/include/linux/ipmi_smi.h
@@ -245,7 +245,7 @@ static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
/* Allow the lower layer to add things to the proc filesystem
directory for this interface. Note that the entry will
automatically be dstroyed when the interface is destroyed. */
-int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
+int ipmi_smi_add_proc_entry(ipmi_smi_t smi, const char *name,
const struct file_operations *proc_ops,
void *data);

--
2.4.10


2015-11-25 13:43:37

by Corentin Labbe

[permalink] [raw]
Subject: [PATCH 2/4] ipmi: constify the reason parameter of start_error_recovery

Both start_error_recovery() function are different but they didn't
modify the reason parameter.
Furthermore, the reason parameter is always given string literal.

Signed-off-by: LABBE Corentin <[email protected]>
---
drivers/char/ipmi/ipmi_kcs_sm.c | 2 +-
drivers/char/ipmi/ipmi_smic_sm.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index 1da61af..9ec38e6 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -202,7 +202,7 @@ static inline void write_next_byte(struct si_sm_data *kcs)
(kcs->write_count)--;
}

-static inline void start_error_recovery(struct si_sm_data *kcs, char *reason)
+static inline void start_error_recovery(struct si_sm_data *kcs, const char *reason)
{
(kcs->error_retries)++;
if (kcs->error_retries > MAX_ERROR_RETRIES) {
diff --git a/drivers/char/ipmi/ipmi_smic_sm.c b/drivers/char/ipmi/ipmi_smic_sm.c
index 8f7c73f..21ad645 100644
--- a/drivers/char/ipmi/ipmi_smic_sm.c
+++ b/drivers/char/ipmi/ipmi_smic_sm.c
@@ -227,7 +227,7 @@ static inline void write_si_sm_data(struct si_sm_data *smic,
smic->io->outputb(smic->io, 0, data);
}

-static inline void start_error_recovery(struct si_sm_data *smic, char *reason)
+static inline void start_error_recovery(struct si_sm_data *smic, const char *reason)
{
(smic->error_retries)++;
if (smic->error_retries > SMIC_MAX_ERROR_RETRIES) {
--
2.4.10

2015-11-25 13:43:41

by Corentin Labbe

[permalink] [raw]
Subject: [PATCH 4/4] ipmi: replace simple_strtoul by kstrtox

The simple_strtoul function is marked as obsolete.
This patch replace it by kstrtoint/kstrtoul.
This will simplify code, since some error case not handled by
simple_strtoul are handled by kstrtox.

Signed-off-by: LABBE Corentin <[email protected]>
---
drivers/char/ipmi/ipmi_si_intf.c | 15 ++++++++-------
drivers/char/ipmi/ipmi_watchdog.c | 8 ++++----
2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index d1fc200..48bab38 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1775,17 +1775,17 @@ static int parse_str(const struct hotmod_vals *v, int *val, char *name,
static int check_hotmod_int_op(const char *curr, const char *option,
const char *name, int *val)
{
- char *n;
+ int err;

if (strcmp(curr, name) == 0) {
if (!option) {
pr_warn(PFX "No option given for '%s'\n", curr);
return -EINVAL;
}
- *val = simple_strtoul(option, &n, 0);
- if ((*n != '\0') || (*option == '\0')) {
+ err = kstrtoint(option, 0, val);
+ if (err) {
pr_warn(PFX "Bad option given for '%s'\n", curr);
- return -EINVAL;
+ return err;
}
return 1;
}
@@ -1805,7 +1805,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
{
char *str = kstrdup(val, GFP_KERNEL);
int rv;
- char *next, *curr, *s, *n, *o;
+ char *next, *curr, *s, *o;
enum hotmod_op op;
enum si_type si_type;
int addr_space;
@@ -1817,6 +1817,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
int ipmb;
int ival;
int len;
+ int err;
struct smi_info *info;

if (!str)
@@ -1862,8 +1863,8 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
*s = '\0';
s++;
}
- addr = simple_strtoul(curr, &n, 0);
- if ((*n != '\0') || (*curr == '\0')) {
+ err = kstrtoul(curr, 0, &addr);
+ if (err) {
pr_warn(PFX "Invalid hotmod address '%s'\n", curr);
break;
}
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 096f0ce..2f0d2c4 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -194,15 +194,15 @@ static int start_now;

static int set_param_timeout(const char *val, const struct kernel_param *kp)
{
- char *endp;
+ int err;
int l;
int rv = 0;

if (!val)
return -EINVAL;
- l = simple_strtoul(val, &endp, 0);
- if (endp == val)
- return -EINVAL;
+ err = kstrtoint(val, 0, &l);
+ if (err)
+ return err;

*((int *)kp->arg) = l;
if (watchdog_user)
--
2.4.10

2015-11-25 14:30:20

by Corentin Labbe

[permalink] [raw]
Subject: [PATCH 3/4] ipmi: Replace all printk(KERN_xxx by their pr_xxx counterpart

This patch replace all printk(KERN_XXX) by their pr_xxx counterparts.
This will also permit to remove some line wrapping.

Signed-off-by: LABBE Corentin <[email protected]>
---
drivers/char/ipmi/ipmi_si_intf.c | 91 +++++++++++++++++-----------------------
1 file changed, 39 insertions(+), 52 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 5a14472..d1fc200 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -1755,7 +1755,7 @@ static int parse_str(const struct hotmod_vals *v, int *val, char *name,

s = strchr(*curr, ',');
if (!s) {
- printk(KERN_WARNING PFX "No hotmod %s given.\n", name);
+ pr_warn(PFX "No hotmod %s given.\n", name);
return -EINVAL;
}
*s = '\0';
@@ -1768,7 +1768,7 @@ static int parse_str(const struct hotmod_vals *v, int *val, char *name,
}
}

- printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr);
+ pr_warn(PFX "Invalid hotmod %s '%s'\n", name, *curr);
return -EINVAL;
}

@@ -1779,16 +1779,12 @@ static int check_hotmod_int_op(const char *curr, const char *option,

if (strcmp(curr, name) == 0) {
if (!option) {
- printk(KERN_WARNING PFX
- "No option given for '%s'\n",
- curr);
+ pr_warn(PFX "No option given for '%s'\n", curr);
return -EINVAL;
}
*val = simple_strtoul(option, &n, 0);
if ((*n != '\0') || (*option == '\0')) {
- printk(KERN_WARNING PFX
- "Bad option given for '%s'\n",
- curr);
+ pr_warn(PFX "Bad option given for '%s'\n", curr);
return -EINVAL;
}
return 1;
@@ -1868,8 +1864,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
}
addr = simple_strtoul(curr, &n, 0);
if ((*n != '\0') || (*curr == '\0')) {
- printk(KERN_WARNING PFX "Invalid hotmod address"
- " '%s'\n", curr);
+ pr_warn(PFX "Invalid hotmod address '%s'\n", curr);
break;
}

@@ -1912,9 +1907,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
continue;

rv = -EINVAL;
- printk(KERN_WARNING PFX
- "Invalid hotmod option '%s'\n",
- curr);
+ pr_warn(PFX "Invalid hotmod option '%s'\n", curr);
goto out;
}

@@ -1994,7 +1987,7 @@ static int hardcode_find_bmc(void)
return -ENOMEM;

info->addr_source = SI_HARDCODED;
- printk(KERN_INFO PFX "probing via hardcoded address\n");
+ pr_info(PFX "probing via hardcoded address\n");

if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
info->si_type = SI_KCS;
@@ -2003,7 +1996,7 @@ static int hardcode_find_bmc(void)
} else if (strcmp(si_type[i], "bt") == 0) {
info->si_type = SI_BT;
} else {
- printk(KERN_WARNING PFX "Interface type specified "
+ pr_warn(PFX "Interface type specified "
"for interface %d, was invalid: %s\n",
i, si_type[i]);
kfree(info);
@@ -2021,7 +2014,7 @@ static int hardcode_find_bmc(void)
info->io.addr_data = addrs[i];
info->io.addr_type = IPMI_MEM_ADDR_SPACE;
} else {
- printk(KERN_WARNING PFX "Interface type specified "
+ pr_warn(PFX "Interface type specified "
"for interface %d, but port and address were "
"not set or set to zero.\n", i);
kfree(info);
@@ -2166,18 +2159,18 @@ static int try_init_spmi(struct SPMITable *spmi)
int rv;

if (spmi->IPMIlegacy != 1) {
- printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy);
+ pr_info(PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy);
return -ENODEV;
}

info = smi_info_alloc();
if (!info) {
- printk(KERN_ERR PFX "Could not allocate SI data (3)\n");
+ pr_err(PFX "Could not allocate SI data (3)\n");
return -ENOMEM;
}

info->addr_source = SI_SPMI;
- printk(KERN_INFO PFX "probing via SPMI\n");
+ pr_info(PFX "probing via SPMI\n");

/* Figure out the interface type. */
switch (spmi->InterfaceType) {
@@ -2194,8 +2187,8 @@ static int try_init_spmi(struct SPMITable *spmi)
kfree(info);
return -EIO;
default:
- printk(KERN_INFO PFX "Unknown ACPI/SPMI SI type %d\n",
- spmi->InterfaceType);
+ pr_info(PFX "Unknown ACPI/SPMI SI type %d\n",
+ spmi->InterfaceType);
kfree(info);
return -EIO;
}
@@ -2231,7 +2224,7 @@ static int try_init_spmi(struct SPMITable *spmi)
info->io.addr_type = IPMI_IO_ADDR_SPACE;
} else {
kfree(info);
- printk(KERN_WARNING PFX "Unknown ACPI I/O Address type\n");
+ pr_warn(PFX "Unknown ACPI I/O Address type\n");
return -EIO;
}
info->io.addr_data = spmi->addr.address;
@@ -2349,12 +2342,12 @@ static void try_init_dmi(struct dmi_ipmi_data *ipmi_data)

info = smi_info_alloc();
if (!info) {
- printk(KERN_ERR PFX "Could not allocate SI data\n");
+ pr_err(PFX "Could not allocate SI data\n");
return;
}

info->addr_source = SI_SMBIOS;
- printk(KERN_INFO PFX "probing via SMBIOS\n");
+ pr_info(PFX "probing via SMBIOS\n");

switch (ipmi_data->type) {
case 0x01: /* KCS */
@@ -2384,8 +2377,8 @@ static void try_init_dmi(struct dmi_ipmi_data *ipmi_data)

default:
kfree(info);
- printk(KERN_WARNING PFX "Unknown SMBIOS I/O Address type: %d\n",
- ipmi_data->addr_space);
+ pr_warn(PFX "Unknown SMBIOS I/O Address type: %d\n",
+ ipmi_data->addr_space);
return;
}
info->io.addr_data = ipmi_data->base_addr;
@@ -3132,7 +3125,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info)

rv = wait_for_msg_done(smi_info);
if (rv) {
- printk(KERN_WARNING PFX "Error getting response from get"
+ pr_warn(PFX "Error getting response from get"
" global enables command, the event buffer is not"
" enabled.\n");
goto out;
@@ -3145,7 +3138,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info)
resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 ||
resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD ||
resp[2] != 0) {
- printk(KERN_WARNING PFX "Invalid return from get global"
+ pr_warn(PFX "Invalid return from get global"
" enables command, cannot enable the event buffer.\n");
rv = -EINVAL;
goto out;
@@ -3164,7 +3157,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info)

rv = wait_for_msg_done(smi_info);
if (rv) {
- printk(KERN_WARNING PFX "Error getting response from set"
+ pr_warn(PFX "Error getting response from set"
" global, enables command, the event buffer is not"
" enabled.\n");
goto out;
@@ -3176,7 +3169,7 @@ static int try_enable_event_buffer(struct smi_info *smi_info)
if (resp_len < 3 ||
resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 ||
resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) {
- printk(KERN_WARNING PFX "Invalid return from get global,"
+ pr_warn(PFX "Invalid return from get global,"
"enables command, not enable the event buffer.\n");
rv = -EINVAL;
goto out;
@@ -3490,7 +3483,7 @@ static void default_find_bmc(void)
if (add_smi(info) == 0) {
if ((try_smi_init(info)) == 0) {
/* Found one... */
- printk(KERN_INFO PFX "Found default %s"
+ pr_info(PFX "Found default %s"
" state machine at %s address 0x%lx\n",
si_to_str[info->si_type],
addr_space_to_str[info->io.addr_type],
@@ -3521,9 +3514,9 @@ static int add_smi(struct smi_info *new_smi)
{
int rv = 0;

- printk(KERN_INFO PFX "Adding %s-specified %s state machine",
- ipmi_addr_src_to_str(new_smi->addr_source),
- si_to_str[new_smi->si_type]);
+ pr_info(PFX "Adding %s-specified %s state machine",
+ ipmi_addr_src_to_str(new_smi->addr_source),
+ si_to_str[new_smi->si_type]);
mutex_lock(&smi_infos_lock);
if (!is_new_interface(new_smi)) {
printk(KERN_CONT " duplicate interface\n");
@@ -3550,7 +3543,7 @@ static int try_smi_init(struct smi_info *new_smi)
int rv = 0;
int i;

- printk(KERN_INFO PFX "Trying %s-specified %s state"
+ pr_info(PFX "Trying %s-specified %s state"
" machine at %s address 0x%lx, slave address 0x%x,"
" irq %d\n",
ipmi_addr_src_to_str(new_smi->addr_source),
@@ -3581,8 +3574,7 @@ static int try_smi_init(struct smi_info *new_smi)
/* Allocate the state machine's data and initialize it. */
new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL);
if (!new_smi->si_sm) {
- printk(KERN_ERR PFX
- "Could not allocate state machine memory\n");
+ pr_err(PFX "Could not allocate state machine memory\n");
rv = -ENOMEM;
goto out_err;
}
@@ -3592,14 +3584,14 @@ static int try_smi_init(struct smi_info *new_smi)
/* Now that we know the I/O size, we can set up the I/O. */
rv = new_smi->io_setup(new_smi);
if (rv) {
- printk(KERN_ERR PFX "Could not set up I/O space\n");
+ pr_err(PFX "Could not set up I/O space\n");
goto out_err;
}

/* Do low-level detection first. */
if (new_smi->handlers->detect(new_smi->si_sm)) {
if (new_smi->addr_source)
- printk(KERN_INFO PFX "Interface detection failed\n");
+ pr_info(PFX "Interface detection failed\n");
rv = -ENODEV;
goto out_err;
}
@@ -3611,7 +3603,7 @@ static int try_smi_init(struct smi_info *new_smi)
rv = try_get_dev_id(new_smi);
if (rv) {
if (new_smi->addr_source)
- printk(KERN_INFO PFX "There appears to be no BMC"
+ pr_info(PFX "There appears to be no BMC"
" at this location\n");
goto out_err;
}
@@ -3659,8 +3651,7 @@ static int try_smi_init(struct smi_info *new_smi)
new_smi->pdev = platform_device_alloc("ipmi_si",
new_smi->intf_num);
if (!new_smi->pdev) {
- printk(KERN_ERR PFX
- "Unable to allocate platform device\n");
+ pr_err(PFX "Unable to allocate platform device\n");
goto out_err;
}
new_smi->dev = &new_smi->pdev->dev;
@@ -3668,7 +3659,7 @@ static int try_smi_init(struct smi_info *new_smi)

rv = platform_device_add(new_smi->pdev);
if (rv) {
- printk(KERN_ERR PFX
+ pr_err(PFX
"Unable to register system interface device:"
" %d\n",
rv);
@@ -3779,8 +3770,7 @@ static int init_ipmi_si(void)
if (si_tryplatform) {
rv = platform_driver_register(&ipmi_driver);
if (rv) {
- printk(KERN_ERR PFX "Unable to register "
- "driver: %d\n", rv);
+ pr_err(PFX "Unable to register driver: %d\n", rv);
return rv;
}
}
@@ -3800,7 +3790,7 @@ static int init_ipmi_si(void)
}
}

- printk(KERN_INFO "IPMI System Interface driver.\n");
+ pr_info("IPMI System Interface driver.\n");

/* If the user gave us a device, they presumably want us to use it */
if (!hardcode_find_bmc())
@@ -3810,8 +3800,7 @@ static int init_ipmi_si(void)
if (si_trypci) {
rv = pci_register_driver(&ipmi_pci_driver);
if (rv)
- printk(KERN_ERR PFX "Unable to register "
- "PCI driver: %d\n", rv);
+ pr_err(PFX "Unable to register PCI driver: %d\n", rv);
else
pci_registered = true;
}
@@ -3885,8 +3874,7 @@ static int init_ipmi_si(void)
if (unload_when_empty && list_empty(&smi_infos)) {
mutex_unlock(&smi_infos_lock);
cleanup_ipmi_si();
- printk(KERN_WARNING PFX
- "Unable to find any System Interface(s)\n");
+ pr_warn(PFX "Unable to find any System Interface(s)\n");
return -ENODEV;
} else {
mutex_unlock(&smi_infos_lock);
@@ -3907,10 +3895,9 @@ static void cleanup_one_si(struct smi_info *to_clean)

to_clean->intf = NULL;
rv = ipmi_unregister_smi(intf);
- if (rv) {
+ if (rv)
pr_err(PFX "Unable to unregister device: errno=%d\n",
rv);
- }
}

if (to_clean->dev)
--
2.4.10