time: Fix signedness bug in sysfs_get_uname() and its callers
Subsystems (3)
PATCH 1/1 time: Fix signedness bug in sysfs_get_uname() and its callers
sysfs_get_uname() is erroneously declared as returning size_t even though it may return a negative value, specifically -EINVAL. Its callers then check whether its return value is less than zero and indeed that is never the case for size_t.
This patch changes sysfs_get_uname() to return ssize_t and makes sure its callers use ssize_t accordingly.
--- kernel/time/clockevents.c | 2 +- kernel/time/clocksource.c | 6 +++--- kernel/time/tick-internal.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
kernel/time/clockevents.c +1 -1
@@ -584,7 +584,7 @@ static ssize_t sysfs_unbind_tick_dev(struct device *dev, const char *buf, size_t count) { char name[CS_NAME_LEN]; -size_t ret =sysfs_get_uname (buf, name, count); +ssize_t ret =sysfs_get_uname (buf, name, count);struct clock_event_device *ce;if (ret <0 )
kernel/time/clocksource.c +3 -3
@@ -893,7 +893,7 @@ sysfs_show_current_clocksources(struct device *dev,return count; } -size_t sysfs_get_uname (const char *buf,char *dst,size_t cnt) +ssize_t sysfs_get_uname (const char *buf,char *dst,size_t cnt) {size_t ret = cnt;
@@ -924,7 +924,7 @@ static ssize_t sysfs_override_clocksource(struct device *dev,struct device_attribute *attr, const char *buf, size_t count) { - size_t ret; + ssize_t ret;mutex_lock (&clocksource_mutex);
@@ -952,7 +952,7 @@ static ssize_t sysfs_unbind_clocksource(struct device *dev, {struct clocksource *cs;char name[CS_NAME_LEN ]; -size_t ret; +ssize_t ret; ret =sysfs_get_uname (buf, name, count);if (ret <0 )
kernel/time/tick-internal.h +1 -1
@@ -31,7 +31,7 @@ extern void tick_install_replacement(struct clock_event_device *dev);extern void clockevents_shutdown (struct clock_event_device *dev); -extern size_t sysfs_get_uname (const char *buf,char *dst,size_t cnt); +extern ssize_t sysfs_get_uname (const char *buf,char *dst,size_t cnt);/* * NO_HZ / high resolution timer shared code
Signature · 1 line
1.8.4.rc3
Quoted 7 lines · Patrick Palka
sysfs_get_uname()is erroneously declared as returningsize_teven though it may return a negative value, specifically-EINVAL. Its callers then check whether its return value is less than zero and indeed that is never the case forsize_t.This patch changes
sysfs_get_uname()to returnssize_tand makes sure its callers usessize_taccordingly.
So a similar fix has already been queued in tip/timers/core, but this seems more complete, so I've resolved the collisions with the earlier fix and queued it for 3.13.
Would you please take a look at the resulting commit and double check I didn't flub the conflict resolution?
thanks
-john
Quoted 9 lines · John Stultz
Quoted 7 lines · Patrick Palka
sysfs_get_uname()is erroneously declared as returningsize_teven though it may return a negative value, specifically-EINVAL. Its callers then check whether its return value is less than zero and indeed that is never the case forsize_t.This patch changes
sysfs_get_uname()to returnssize_tand makes sure its callers usessize_taccordingly.
Quoted 8 lines
So a similar fix has already been queued in tip/timers/core, but this seems more complete, so I've resolved the collisions with the earlier fix and queued it for 3.13.
Would you please take a look at the resulting commit and double check I didn't flub the conflict resolution?
Looks good.