Skip to content

Commit

Permalink
cifs: call strtobool instead of custom implementation
Browse files Browse the repository at this point in the history
Meanwhile it cleans up the code, the behaviour is slightly changed. In case of
providing non-boolean value it will fails with corresponding error. In the
original code the attempt of an update was just ignored in such case.

Signed-off-by: Andy Shevchenko <[email protected]>
Acked-by: Jeff Layton <[email protected]>
Reviewed-by: Alexander Bokovoy <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
andy-shev authored and Steve French committed Dec 8, 2014
1 parent bb1d5dd commit 28e2aed
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions fs/cifs/cifs_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *ppos)
{
char c;
bool bv;
int rc;
struct list_head *tmp1, *tmp2, *tmp3;
struct TCP_Server_Info *server;
Expand All @@ -284,7 +285,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
if (rc)
return rc;

if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
if (strtobool(&c, &bv) == 0) {
#ifdef CONFIG_CIFS_STATS2
atomic_set(&totBufAllocCount, 0);
atomic_set(&totSmBufAllocCount, 0);
Expand Down Expand Up @@ -451,15 +452,14 @@ static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
{
char c;
bool bv;
int rc;

rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
cifsFYI = 0;
else if (c == '1' || c == 'y' || c == 'Y')
cifsFYI = 1;
if (strtobool(&c, &bv) == 0)
cifsFYI = bv;
else if ((c > '1') && (c <= '9'))
cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */

Expand Down Expand Up @@ -490,15 +490,18 @@ static ssize_t cifs_linux_ext_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *ppos)
{
char c;
bool bv;
int rc;

rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
linuxExtEnabled = 0;
else if (c == '1' || c == 'y' || c == 'Y')
linuxExtEnabled = 1;

rc = strtobool(&c, &bv);
if (rc)
return rc;

linuxExtEnabled = bv;

return count;
}
Expand Down Expand Up @@ -527,15 +530,18 @@ static ssize_t cifs_lookup_cache_proc_write(struct file *file,
const char __user *buffer, size_t count, loff_t *ppos)
{
char c;
bool bv;
int rc;

rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
lookupCacheEnabled = 0;
else if (c == '1' || c == 'y' || c == 'Y')
lookupCacheEnabled = 1;

rc = strtobool(&c, &bv);
if (rc)
return rc;

lookupCacheEnabled = bv;

return count;
}
Expand Down Expand Up @@ -564,15 +570,18 @@ static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
{
char c;
bool bv;
int rc;

rc = get_user(c, buffer);
if (rc)
return rc;
if (c == '0' || c == 'n' || c == 'N')
traceSMB = 0;
else if (c == '1' || c == 'y' || c == 'Y')
traceSMB = 1;

rc = strtobool(&c, &bv);
if (rc)
return rc;

traceSMB = bv;

return count;
}
Expand Down Expand Up @@ -630,6 +639,7 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
unsigned int flags;
char flags_string[12];
char c;
bool bv;

if ((count < 1) || (count > 11))
return -EINVAL;
Expand All @@ -642,11 +652,8 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
if (count < 3) {
/* single char or single char followed by null */
c = flags_string[0];
if (c == '0' || c == 'n' || c == 'N') {
global_secflags = CIFSSEC_DEF; /* default */
return count;
} else if (c == '1' || c == 'y' || c == 'Y') {
global_secflags = CIFSSEC_MAX;
if (strtobool(&c, &bv) == 0) {
global_secflags = bv ? CIFSSEC_MAX : CIFSSEC_DEF;
return count;
} else if (!isdigit(c)) {
cifs_dbg(VFS, "Invalid SecurityFlags: %s\n",
Expand Down

0 comments on commit 28e2aed

Please sign in to comment.