Bug 44131

Summary: i7300_edac.c: 2 * bad macro test
Product: Drivers Reporter: David Binderman (dcb314)
Component: EDACAssignee: Mauro Carvalho Chehab (mchehab)
Status: RESOLVED CODE_FIX    
Severity: normal CC: florian, jdelvare
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.5-rc5 Subsystem:
Regression: No Bisected commit-id:
Attachments: i7300_edac: Fix error flag testing

Description David Binderman 2012-07-02 20:29:17 UTC
I just ran the static analyser cppcheck over the source code of the
linux kernel version 3.5-rc5.

It said

[linux-3.5-rc5/drivers/edac/i7300_edac.c:449]: (style) Expression '(X & 0x30000000) == 0x2' is always false
[linux-3.5-rc5/drivers/edac/i7300_edac.c:485]: (style) Expression '(X & 0x30000000) == 0x2' is always false

The source codes are

        branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;

and
        branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;

but

#define GET_FBD_FAT_IDX(fbderr) (fbderr & (3 << 28))

so I agree with the analyser. Suggest code rework.
Comment 1 Jean Delvare 2012-10-18 13:56:51 UTC
Good catch, thanks for reporting.
Comment 2 Jean Delvare 2012-10-18 13:57:41 UTC
Created attachment 83851 [details]
i7300_edac: Fix error flag testing

Candidate fix, needs review and testing.
Comment 3 Florian Mickler 2012-12-15 03:31:05 UTC
A patch referencing this bug report has been merged in Linux v3.7-rc8:

commit 7e06b7a3333f5c7a0cec12aff20d39c5c87c0795
Author: Jean Delvare <jdelvare@suse.de>
Date:   Thu Oct 18 15:54:45 2012 +0200

    i7300_edac: Fix error flag testing