public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Andrzej Hajda <a.hajda@samsung•com>
To: David Howells <dhowells@redhat•com>
Cc: linux-mips@linux-mips•org, linux-fbdev@vger•kernel.org,
	linux-sh@vger•kernel.org, brcm80211-dev-list@broadcom•com,
	dri-devel@lists•freedesktop.org, linux-mm@kvack•org,
	linux-clk@vger•kernel.org, linux-leds@vger•kernel.org,
	Marek Szyprowski <m.szyprowski@samsung•com>,
	devel@driverdev•osuosl.org, linux-rdma@vger•kernel.org,
	linux-cachefs@redhat•com, linux-serial@vger•kernel.org,
	linux-input@vger•kernel.org, linux-media@vger•kernel.org,
	dev@openvswitch•org, rtc-linux@googlegroups•com,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung•com>,
	intel-gfx@lists•freedesktop.org, linux-omap@vger•kernel.org,
	linux-arm-kernel@lists•infradead.org,
	Andrzej Hajda <a.hajda@samsung•com>,
	linux-api@vger•kernel.org, linux-usb@vger•kernel.org,
	linux-wireless@vger•kernel.org, linux-kernel@vger•kernel.org,
	linux-crypto@vger•kernel.org, netdev@vger•kernel.org,
	lustre-devel@lists•lustre.org
Subject: Re: [PATCH 00/38] Fixes related to incorrect usage of unsigned types
Date: Tue, 22 Sep 2015 11:13:29 +0200	[thread overview]
Message-ID: <56011BB9.5030004@samsung.com> (raw)
In-Reply-To: <17571.1442842945@warthog.procyon.org.uk>

On 09/21/2015 03:42 PM, David Howells wrote:
> Andrzej Hajda <a.hajda-Sze3O3UU22JBDgjK7y7TUQ@public•gmane.org> wrote:
> 
>> Semantic patch finds comparisons of types:
>>     unsigned < 0
>>     unsigned >= 0
>> The former is always false, the latter is always true.
>> Such comparisons are useless, so theoretically they could be
>> safely removed, but their presence quite often indicates bugs.
> 
> Or someone has left them in because they don't matter and there's the
> possibility that the type being tested might be or become signed under some
> circumstances.  If the comparison is useless, I'd expect the compiler to just
> discard it - for such cases your patch is pointless.
> 
> If I have, for example:
> 
> 	unsigned x;
> 
> 	if (x == 0 || x > 27)
> 		give_a_range_error();
> 
> I will write this as:
> 
> 	unsigned x;
> 
> 	if (x <= 0 || x > 27)
> 		give_a_range_error();
> 
> because it that gives a way to handle x being changed to signed at some point
> in the future for no cost.  In which case, your changing the <= to an ==
> "because the < part of the case is useless" is arguably wrong.

This is why I have not checked for such cases - I have skipped checks of type
	unsigned <= 0
exactly for the reasons above.

However I have left two other checks as they seems to me more suspicious - they
are always true or false. But as Dmitry and Andrew pointed out Linus have quite
strong opinion against removing range checks in such cases as he finds it
clearer. I think it applies to patches 29-36. I am not sure about patches 26-28,37.

Regards
Andrzej

> 
> David
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public•gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists•freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2015-09-22  9:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-21 13:33 [PATCH 00/38] Fixes related to incorrect usage of unsigned types Andrzej Hajda
     [not found] ` <1442842450-29769-1-git-send-email-a.hajda-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-09-21 13:33   ` [PATCH 08/38] openvswitch: fix handling result of ipv6_skip_exthdr Andrzej Hajda
2015-09-21 17:45     ` Pravin Shelar
2015-09-21 13:33 ` [PATCH 17/38] isdn: hisax: fix frame calculation Andrzej Hajda
2015-09-22 23:15   ` David Miller
2015-09-21 13:33 ` [PATCH 18/38] net/ibm/emac: fix type of phy_mode Andrzej Hajda
2015-09-22 23:14   ` David Miller
2015-09-21 13:33 ` [PATCH 19/38] net: stmmac: fix type of entry variable Andrzej Hajda
2015-09-22 23:15   ` David Miller
2015-09-21 13:33 ` [PATCH 20/38] net: brcm80211: fix range check Andrzej Hajda
2015-09-22 23:15   ` David Miller
2015-09-21 13:33 ` [PATCH 21/38] mwifiex: fix comparison expression Andrzej Hajda
2015-09-22 10:56   ` Amitkumar Karwar
2015-09-22 23:15   ` David Miller
2015-09-21 13:33 ` [PATCH 22/38] orinoco: fix checking for default value Andrzej Hajda
2015-09-22 23:15   ` David Miller
2015-09-21 13:33 ` [PATCH 23/38] rndis_wlan: " Andrzej Hajda
2015-09-22 23:15   ` David Miller
2015-09-21 13:33 ` [PATCH 27/38] usbnet: remove invalid check Andrzej Hajda
2015-09-22 23:15   ` David Miller
     [not found] ` <17571.1442842945@warthog.procyon.org.uk>
2015-09-22  9:13   ` Andrzej Hajda [this message]
2015-09-22  9:46     ` [PATCH 00/38] Fixes related to incorrect usage of unsigned types Jacek Anaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56011BB9.5030004@samsung.com \
    --to=a.hajda@samsung$(echo .)com \
    --cc=b.zolnierkie@samsung$(echo .)com \
    --cc=brcm80211-dev-list@broadcom$(echo .)com \
    --cc=dev@openvswitch$(echo .)org \
    --cc=devel@driverdev$(echo .)osuosl.org \
    --cc=dhowells@redhat$(echo .)com \
    --cc=dri-devel@lists$(echo .)freedesktop.org \
    --cc=intel-gfx@lists$(echo .)freedesktop.org \
    --cc=linux-api@vger$(echo .)kernel.org \
    --cc=linux-arm-kernel@lists$(echo .)infradead.org \
    --cc=linux-cachefs@redhat$(echo .)com \
    --cc=linux-clk@vger$(echo .)kernel.org \
    --cc=linux-crypto@vger$(echo .)kernel.org \
    --cc=linux-fbdev@vger$(echo .)kernel.org \
    --cc=linux-input@vger$(echo .)kernel.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-leds@vger$(echo .)kernel.org \
    --cc=linux-media@vger$(echo .)kernel.org \
    --cc=linux-mips@linux-mips$(echo .)org \
    --cc=linux-mm@kvack$(echo .)org \
    --cc=linux-omap@vger$(echo .)kernel.org \
    --cc=linux-rdma@vger$(echo .)kernel.org \
    --cc=linux-serial@vger$(echo .)kernel.org \
    --cc=linux-sh@vger$(echo .)kernel.org \
    --cc=linux-usb@vger$(echo .)kernel.org \
    --cc=linux-wireless@vger$(echo .)kernel.org \
    --cc=lustre-devel@lists$(echo .)lustre.org \
    --cc=m.szyprowski@samsung$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=rtc-linux@googlegroups$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox