Wrong type in sscanf format string, requires 'int *' but the
argument type is 'unsigned int *'
This was found using a static code analysis program called cppcheck
Signed-off-by: Rickard Strandqvist <[email protected]>
---
drivers/video/fbdev/omap/omapfb_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index d8d028d..7df0764 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -1371,7 +1371,7 @@ static ssize_t omapfb_store_bklight_level(struct device *dev,
if (fbdev->panel->set_bklight_level) {
unsigned int level;
- if (sscanf(buf, "%10d", &level) == 1) {
+ if (sscanf(buf, "%10u", &level) == 1) {
r = fbdev->panel->set_bklight_level(fbdev->panel,
level);
} else
--
1.7.10.4
On Sun, 2014-07-06 at 19:34 +0200, Rickard Strandqvist wrote:
> Wrong type in sscanf format string, requires 'int *' but the
> argument type is 'unsigned int *'
Maybe use kstrtouint?
> diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
> @@ -1371,7 +1371,7 @@ static ssize_t omapfb_store_bklight_level(struct device *dev,
> if (fbdev->panel->set_bklight_level) {
> unsigned int level;
>
> - if (sscanf(buf, "%10d", &level) == 1) {
> + if (sscanf(buf, "%10u", &level) == 1) {
> r = fbdev->panel->set_bklight_level(fbdev->panel,
> level);
> } else
Something like: (more comments below patch too)
drivers/video/fbdev/omap/omapfb_main.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/drivers/video/fbdev/omap/omapfb_main.c b/drivers/video/fbdev/omap/omapfb_main.c
index d8d028d..96dd2f0 100644
--- a/drivers/video/fbdev/omap/omapfb_main.c
+++ b/drivers/video/fbdev/omap/omapfb_main.c
@@ -1365,20 +1365,16 @@ static ssize_t omapfb_store_bklight_level(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
+ unsigned int level;
struct omapfb_device *fbdev = dev_get_drvdata(dev);
- int r;
- if (fbdev->panel->set_bklight_level) {
- unsigned int level;
+ if (!fbdev->panel->set_bklight_level)
+ return -ENODEV;
- if (sscanf(buf, "%10d", &level) == 1) {
- r = fbdev->panel->set_bklight_level(fbdev->panel,
- level);
- } else
- r = -EINVAL;
- } else
- r = -ENODEV;
- return r ? r : size;
+ if (kstrtouint(buf, 10, &level) < 0)
+ return -EINVAL;
+
+ return fbdev->panel->set_bklight_level(fbdev->panel, level) ?: size;
}
static ssize_t omapfb_show_bklight_max(struct device *dev,
---
The brightness permissions seem odd:
drivers/video/fbdev/omap/omapfb_main.c-static struct device_attribute dev_attr_panel_name =
drivers/video/fbdev/omap/omapfb_main.c- __ATTR(name, 0444, omapfb_show_panel_name, NULL);
drivers/video/fbdev/omap/omapfb_main.c-static DEVICE_ATTR(backlight_level, 0664,
drivers/video/fbdev/omap/omapfb_main.c: omapfb_show_bklight_level, omapfb_store_bklight_level);
drivers/video/fbdev/omap/omapfb_main.c-static DEVICE_ATTR(backlight_max, 0444, omapfb_show_bklight_max, NULL);
Why 0644 for backlight_level when backlight_max is 0444?