From nobody@FreeBSD.org  Tue Nov  8 00:02:53 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 2AC841065673
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  8 Nov 2011 00:02:53 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 0FE978FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  8 Nov 2011 00:02:53 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id pA802qwA069246
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 8 Nov 2011 00:02:52 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id pA802quv069245;
	Tue, 8 Nov 2011 00:02:52 GMT
	(envelope-from nobody)
Message-Id: <201111080002.pA802quv069245@red.freebsd.org>
Date: Tue, 8 Nov 2011 00:02:52 GMT
From: Alexander Best <arundel@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [ath] several shifts overflowing in sys/dev/ath code
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         162366
>Category:       kern
>Synopsis:       [ath] several shifts overflowing in sys/dev/ath code
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    dim
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 08 00:10:06 UTC 2011
>Closed-Date:    Mon Jan 09 11:38:45 UTC 2012
>Last-Modified:  Mon Jan 09 11:38:45 UTC 2012
>Originator:     Alexander Best
>Release:        10.0-CURRENT
>Organization:
>Environment:
FreeBSD otaku 10.0-CURRENT FreeBSD 10.0-CURRENT #6: Fri Nov  4 14:33:13 CET 2011     arundel@otaku:/usr/obj/usr/git-freebsd-head/sys/ARUNDEL  amd64
>Description:
clang warns about several shift overflows in sys/dev/ath code:

/usr/git-freebsd-head/sys/dev/ath/ath_hal/ar5210/ar5210_power.c:36:3: warning: signed shift result (0x200000000) requires 35 bits to represent, but 'int' only has 32 bits [-Wshift-overflow]
                OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_ALLOW);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/git-freebsd-head/sys/dev/ath/ath_hal/ah_internal.h:471:42: note: expanded from macro 'OS_REG_RMW_FIELD'
                (OS_REG_READ(_a, _r) &~ (_f)) | (((_v) << _f##_S) & (_f)))
                                                       ^
/usr/git-freebsd-head/sys/dev/ath/ah_osdep.h:127:49: note: expanded from macro 'OS_REG_WRITE'
            (bus_space_handle_t)(_ah)->ah_sh, (_reg), (_val))
                                                       ^~~~
/usr/git-freebsd-head/sys/dev/ath/ath_hal/ar5210/ar5210_power.c:90:3: warning: signed shift result (0x100000000) requires 34 bits to represent, but 'int' only has 32 bits [-Wshift-overflow]
                OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_SLP);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/git-freebsd-head/sys/dev/ath/ath_hal/ah_internal.h:471:42: note: expanded from macro 'OS_REG_RMW_FIELD'
                (OS_REG_READ(_a, _r) &~ (_f)) | (((_v) << _f##_S) & (_f)))
                                                       ^
/usr/git-freebsd-head/sys/dev/ath/ah_osdep.h:127:49: note: expanded from macro 'OS_REG_WRITE'
            (bus_space_handle_t)(_ah)->ah_sh, (_reg), (_val))
                                                       ^~~~
2 warnings generated.

/usr/git-freebsd-head/sys/dev/ath/ath_hal/ar5211/ar5211_power.c:79:3: warning: signed shift result (0x100000000) requires 34 bits to represent, but 'int' only has 32 bits [-Wshift-overflow]
                OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_SLP);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/git-freebsd-head/sys/dev/ath/ath_hal/ah_internal.h:471:42: note: expanded from macro 'OS_REG_RMW_FIELD'
                (OS_REG_READ(_a, _r) &~ (_f)) | (((_v) << _f##_S) & (_f)))
                                                       ^
/usr/git-freebsd-head/sys/dev/ath/ah_osdep.h:127:49: note: expanded from macro 'OS_REG_WRITE'
            (bus_space_handle_t)(_ah)->ah_sh, (_reg), (_val))
                                                       ^~~~
/usr/git-freebsd-head/sys/dev/ath/ath_hal/ar5211/ar5211_power.c:92:3: warning: signed shift result (0x200000000) requires 35 bits to represent, but 'int' only has 32 bits [-Wshift-overflow]
                OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_NORM);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/git-freebsd-head/sys/dev/ath/ath_hal/ah_internal.h:471:42: note: expanded from macro 'OS_REG_RMW_FIELD'
                (OS_REG_READ(_a, _r) &~ (_f)) | (((_v) << _f##_S) & (_f)))
                                                       ^
/usr/git-freebsd-head/sys/dev/ath/ah_osdep.h:127:49: note: expanded from macro 'OS_REG_WRITE'
            (bus_space_handle_t)(_ah)->ah_sh, (_reg), (_val))
                                                       ^~~~
2 warnings generated.

dimitry andric explained in [1] that at least the first case appears to be a real bug and not a bogus compiler warning. the other cases need to be investigated in detail, too.

[1] http://lists.freebsd.org/pipermail/freebsd-toolchain/2011-November/000282.html
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->adrian 
Responsible-Changed-By: arundel 
Responsible-Changed-When: Tue Nov 8 00:10:48 UTC 2011 
Responsible-Changed-Why:  
Adrian volunteered to take a glimpse at these warnings -- possibly ath(4) bugs. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162366 

From: Alexander Best <arundel@freebsd.org>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: kern/162366: [ath] several shifts overflowing in sys/dev/ath code
Date: Sat, 3 Dec 2011 12:46:25 +0000

 i also found the following clang warning/error. this is different from the
 bogus "-Wshift-count-negative" warnings/errors and the "-Wshift-overflow"
 warnings/errors, reported in the initial problem report. it only occurs once,
 so i tend to believe this is a report of a real issue:
 
 /usr/subversion-src/sys/dev/ath/ath_hal/ah_regdomain/ah_rd_domains.h:629:15: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
          .chan11a               = BM4(W2_5260_5320,
                                   ^~~~~~~~~~~~~~~~~
 
 cheers.
 alex
State-Changed-From-To: open->patched 
State-Changed-By: arundel 
State-Changed-When: Wed Dec 21 20:01:36 UTC 2011 
State-Changed-Why:  
fixed in r228785. the -Wshift-count-overflow warning in my followup from 
"Sat, 3 Dec 2011" was a false positive and the warning was disabled in r228783. 

so r228783 and r228785 should probably be mfc'ed together. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162366 
Responsible-Changed-From-To: adrian->dim 
Responsible-Changed-By: arundel 
Responsible-Changed-When: Wed Dec 21 20:06:47 UTC 2011 
Responsible-Changed-Why:  
over to dim@ as mfc reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162366 
State-Changed-From-To: patched->closed 
State-Changed-By: dim 
State-Changed-When: Mon Jan 9 11:38:12 UTC 2012 
State-Changed-Why:  
Merged to stable/9 in r229733. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=162366 
>Unformatted:
