From nobody@FreeBSD.org  Wed Mar 20 22:41:29 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 6EB52DFE
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Mar 2013 22:41:29 +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 5FB1A91D
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Mar 2013 22:41:29 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r2KMfTnE024972
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Mar 2013 22:41:29 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r2KMfT1b024964;
	Wed, 20 Mar 2013 22:41:29 GMT
	(envelope-from nobody)
Message-Id: <201303202241.r2KMfT1b024964@red.freebsd.org>
Date: Wed, 20 Mar 2013 22:41:29 GMT
From: hiren panchasara <hiren.panchasara@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] Fixing clang warnings at /sys/geom
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         177165
>Category:       kern
>Synopsis:       [patch] Fixing clang warnings at /sys/geom
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    hiren
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 20 22:50:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Mon Apr 29 07:12:53 UTC 2013
>Originator:     hiren panchasara
>Release:        current
>Organization:
>Environment:
10.0-CURRENT FreeBSD 10.0-CURRENT #1 r248555: Wed Mar 20 15:00:20 UTC 2013
>Description:
===> geom/geom_cache (all)
/usr/src/sys/modules/geom/geom_cache/../../../geom/cache/g_cache.c:76:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]   
        if (val < 0 || val > 100)
            ~~~ ^ ~
1 warning generated.

===> geom/geom_journal (all)
/usr/src/sys/modules/geom/geom_journal/../../../geom/journal/g_journal.c:178:14: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
        if (cswitch < 0 || cswitch > 100)
            ~~~~~~~ ^ ~
1 warning generated.

===> geom/geom_raid (all)
/usr/src/sys/modules/geom/geom_raid/../../../geom/raid/tr_raid5.c:109:11: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
            qual >= 0 && qual <= 1) {
            ~~~~ ^  ~
/usr/src/sys/modules/geom/geom_raid/../../../geom/raid/tr_raid5.c:117:11: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
            qual >= 0 && qual <= 3) {
            ~~~~ ^  ~
2 warnings generated.

>How-To-Repeat:
cd /sys/modules/geom and do "make" to see clang warnings.
>Fix:
Index: sys/geom/cache/g_cache.c
===================================================================
--- sys/geom/cache/g_cache.c    (revision 248555)
+++ sys/geom/cache/g_cache.c    (working copy)
@@ -73,7 +73,7 @@
        error = sysctl_handle_int(oidp, &val, 0, req);
        if (error || !req->newptr)
                return (error);
-       if (val < 0 || val > 100)
+       if (val > 100)
                return (EINVAL);
        if ((arg1 == &g_cache_used_lo && val > g_cache_used_hi) ||
            (arg1 == &g_cache_used_hi && g_cache_used_lo > val))
Index: sys/geom/journal/g_journal.c
===================================================================
--- sys/geom/journal/g_journal.c        (revision 248555)
+++ sys/geom/journal/g_journal.c        (working copy)
@@ -175,7 +175,7 @@
        error = sysctl_handle_int(oidp, &cswitch, 0, req);
        if (error != 0 || req->newptr == NULL)
                return (error);
-       if (cswitch < 0 || cswitch > 100)
+       if (cswitch > 100)
                return (EINVAL);
        g_journal_cache_switch = cswitch;
        g_journal_cache_low = (g_journal_cache_limit / 100) * cswitch;
Index: sys/geom/raid/tr_raid5.c
===================================================================
--- sys/geom/raid/tr_raid5.c    (revision 248555)
+++ sys/geom/raid/tr_raid5.c    (working copy)
@@ -106,7 +106,7 @@
        trs = (struct g_raid_tr_raid5_object *)tr;
        qual = tr->tro_volume->v_raid_level_qualifier;
        if (tr->tro_volume->v_raid_level == G_RAID_VOLUME_RL_RAID4 &&
-           qual >= 0 && qual <= 1) {
+           qual <= 1) {
                /* RAID4 */
        } else if ((tr->tro_volume->v_raid_level == G_RAID_VOLUME_RL_RAID5 ||
             tr->tro_volume->v_raid_level == G_RAID_VOLUME_RL_RAID5E ||
@@ -114,7 +114,7 @@
             tr->tro_volume->v_raid_level == G_RAID_VOLUME_RL_RAID5R ||
             tr->tro_volume->v_raid_level == G_RAID_VOLUME_RL_RAID6 ||
             tr->tro_volume->v_raid_level == G_RAID_VOLUME_RL_RAIDMDF) &&
-           qual >= 0 && qual <= 3) {
+           qual <= 3) {
                /* RAID5/5E/5EE/5R/6/MDF */
        } else  
                return (G_RAID_TR_TASTE_FAIL);


>Release-Note:
>Audit-Trail:

From: hiren panchasara <hiren@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/177165: [patch] Fixing clang warnings at /sys/geom
Date: Mon, 29 Apr 2013 00:09:17 -0700

 Looking at the patch again,
 
 val in g_cache.c and cswitch in g_journal.c both can be changed to
 "int" from "u_int".
 
 Need someone smarter than myself to point out what is the correct fix.
 
 cheers,
 Hiren
Responsible-Changed-From-To: freebsd-bugs->hiren 
Responsible-Changed-By: hiren 
Responsible-Changed-When: Mon Apr 29 07:11:49 UTC 2013 
Responsible-Changed-Why:  
My own pr and patch. 

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