mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 03:27:44 -04:00
libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value
[ Upstream commit 2e41f274f9aa71cdcc69dc1f26a3f9304a651804 ]
Patch series "fix error when writing negative value to simple attribute
files".
The simple attribute files do not accept a negative value since the commit
488dac0c9237 ("libfs: fix error cast of negative value in
simple_attr_write()"), but some attribute files want to accept a negative
value.
This patch (of 3):
The simple attribute files do not accept a negative value since the commit
488dac0c9237 ("libfs: fix error cast of negative value in
simple_attr_write()"), so we have to use a 64-bit value to write a
negative value.
This adds DEFINE_SIMPLE_ATTRIBUTE_SIGNED for a signed value.
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Fixes: 488dac0c9237 ("libfs: fix error cast of negative value in simple_attr_write()")
Signed-off-by: Akinobu Mita <[email protected]>
Reported-by: Zhao Gongyi <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Oscar Salvador <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Shuah Khan <[email protected]>
Cc: Wei Yongjun <[email protected]>
Cc: Yicong Yang <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
This commit is contained in:
parent
75940697c0
commit
6fc6461672
2 changed files with 29 additions and 5 deletions
22
fs/libfs.c
22
fs/libfs.c
|
|
@ -883,8 +883,8 @@ out:
|
|||
EXPORT_SYMBOL_GPL(simple_attr_read);
|
||||
|
||||
/* interpret the buffer as a number to call the set function with */
|
||||
ssize_t simple_attr_write(struct file *file, const char __user *buf,
|
||||
size_t len, loff_t *ppos)
|
||||
static ssize_t simple_attr_write_xsigned(struct file *file, const char __user *buf,
|
||||
size_t len, loff_t *ppos, bool is_signed)
|
||||
{
|
||||
struct simple_attr *attr;
|
||||
unsigned long long val;
|
||||
|
|
@ -905,7 +905,10 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
|
|||
goto out;
|
||||
|
||||
attr->set_buf[size] = '\0';
|
||||
ret = kstrtoull(attr->set_buf, 0, &val);
|
||||
if (is_signed)
|
||||
ret = kstrtoll(attr->set_buf, 0, &val);
|
||||
else
|
||||
ret = kstrtoull(attr->set_buf, 0, &val);
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = attr->set(attr->data, val);
|
||||
|
|
@ -915,8 +918,21 @@ out:
|
|||
mutex_unlock(&attr->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t simple_attr_write(struct file *file, const char __user *buf,
|
||||
size_t len, loff_t *ppos)
|
||||
{
|
||||
return simple_attr_write_xsigned(file, buf, len, ppos, false);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(simple_attr_write);
|
||||
|
||||
ssize_t simple_attr_write_signed(struct file *file, const char __user *buf,
|
||||
size_t len, loff_t *ppos)
|
||||
{
|
||||
return simple_attr_write_xsigned(file, buf, len, ppos, true);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(simple_attr_write_signed);
|
||||
|
||||
/**
|
||||
* generic_fh_to_dentry - generic helper for the fh_to_dentry export operation
|
||||
* @sb: filesystem to do the file handle conversion on
|
||||
|
|
|
|||
Loading…
Reference in a new issue