Skip to content

Commit

Permalink
hwmon: (ftsteutates) Fix potential memory access error
Browse files Browse the repository at this point in the history
Using set_bit() to set a bit in an integer is not a good idea, since
the function expects an unsigned long as argument, which can be 64 bit
wide. Coverity reports this problem as

>>>     CID 1364488:  Memory - illegal accesses  (INCOMPATIBLE_CAST)
>>>     Pointer "&ret" points to an object whose effective type is "int"
>>>	(32 bits, signed) but is dereferenced as a wider "unsigned
+long" (64 bits, unsigned).  This may lead to memory corruption.
245                     set_bit(1, (unsigned long *)&ret);

Just use BIT instead.

Cc: Thilo Cestonaro <thilo@cestona.ro>
Fixes: 08426ed ("hwmon: Add driver for FTS BMC chip "Teutates"")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Guenter Roeck committed Jul 31, 2016
1 parent 1aa4f02 commit 4c8702b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/hwmon/ftsteutates.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static int fts_wd_set_resolution(struct fts_data *data,
}

if (resolution == seconds)
set_bit(1, (unsigned long *)&ret);
ret |= BIT(1);
else
ret &= ~BIT(1);

Expand Down

0 comments on commit 4c8702b

Please sign in to comment.