Commit 004a04b9 authored by Breno Leitao's avatar Breno Leitao Committed by Jakub Kicinski

netconsole: Use kstrtobool() instead of kstrtoint()

Replace kstrtoint() by kstrtobool() in the sysfs _store() functions.
This improves the user usability and simplify the code.

With this fix, it is now possible to use [YyNn] to set and unset a
feature. Old behaviour is still unchanged.

kstrtobool() is also safer and doesn't need the extra validation that
is required when converting a string to bool (end field in the struct),
which makes the code simpler.
Suggested-by: default avatarPetr Mladek <pmladek@suse.com>
Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/20230721092146.4036622-2-leitao@debian.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 9f64b6e4
...@@ -333,17 +333,15 @@ static ssize_t enabled_store(struct config_item *item, ...@@ -333,17 +333,15 @@ static ssize_t enabled_store(struct config_item *item,
{ {
struct netconsole_target *nt = to_target(item); struct netconsole_target *nt = to_target(item);
unsigned long flags; unsigned long flags;
int enabled; bool enabled;
int err; int err;
mutex_lock(&dynamic_netconsole_mutex); mutex_lock(&dynamic_netconsole_mutex);
err = kstrtoint(buf, 10, &enabled); err = kstrtobool(buf, &enabled);
if (err < 0) if (err)
goto out_unlock; goto out_unlock;
err = -EINVAL; err = -EINVAL;
if (enabled < 0 || enabled > 1)
goto out_unlock;
if ((bool)enabled == nt->enabled) { if ((bool)enabled == nt->enabled) {
pr_info("network logging has already %s\n", pr_info("network logging has already %s\n",
nt->enabled ? "started" : "stopped"); nt->enabled ? "started" : "stopped");
...@@ -394,7 +392,7 @@ static ssize_t release_store(struct config_item *item, const char *buf, ...@@ -394,7 +392,7 @@ static ssize_t release_store(struct config_item *item, const char *buf,
size_t count) size_t count)
{ {
struct netconsole_target *nt = to_target(item); struct netconsole_target *nt = to_target(item);
int release; bool release;
int err; int err;
mutex_lock(&dynamic_netconsole_mutex); mutex_lock(&dynamic_netconsole_mutex);
...@@ -405,13 +403,9 @@ static ssize_t release_store(struct config_item *item, const char *buf, ...@@ -405,13 +403,9 @@ static ssize_t release_store(struct config_item *item, const char *buf,
goto out_unlock; goto out_unlock;
} }
err = kstrtoint(buf, 10, &release); err = kstrtobool(buf, &release);
if (err < 0) if (err)
goto out_unlock;
if (release < 0 || release > 1) {
err = -EINVAL;
goto out_unlock; goto out_unlock;
}
nt->release = release; nt->release = release;
...@@ -426,7 +420,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf, ...@@ -426,7 +420,7 @@ static ssize_t extended_store(struct config_item *item, const char *buf,
size_t count) size_t count)
{ {
struct netconsole_target *nt = to_target(item); struct netconsole_target *nt = to_target(item);
int extended; bool extended;
int err; int err;
mutex_lock(&dynamic_netconsole_mutex); mutex_lock(&dynamic_netconsole_mutex);
...@@ -437,13 +431,9 @@ static ssize_t extended_store(struct config_item *item, const char *buf, ...@@ -437,13 +431,9 @@ static ssize_t extended_store(struct config_item *item, const char *buf,
goto out_unlock; goto out_unlock;
} }
err = kstrtoint(buf, 10, &extended); err = kstrtobool(buf, &extended);
if (err < 0) if (err)
goto out_unlock;
if (extended < 0 || extended > 1) {
err = -EINVAL;
goto out_unlock; goto out_unlock;
}
nt->extended = extended; nt->extended = extended;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment