netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: joe@perches.com
Cc: jeffrey.t.kirsher@intel.com, jesse.brandeburg@intel.com,
	netdev@vger.kernel.org, gospo@redhat.com, sassmann@redhat.com
Subject: Re: [net 5/6] i40e: better return values
Date: Tue, 24 Sep 2013 10:12:31 -0400 (EDT)	[thread overview]
Message-ID: <20130924.101231.1193830264265403478.davem@davemloft.net> (raw)
In-Reply-To: <1380022486.3575.74.camel@joe-AO722>

From: Joe Perches <joe@perches.com>
Date: Tue, 24 Sep 2013 04:34:46 -0700

> On Tue, 2013-09-24 at 02:45 -0700, Jeff Kirsher wrote:
> 
>> diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
> []
>> @@ -3339,9 +3345,7 @@ static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
>>  	/* Traffic class index starts from zero so
>>  	 * increment to return the actual count
>>  	 */
>> -	num_tc++;
>> -
>> -	return num_tc;
>> +	return num_tc++;
> 
> Ick.  post_increment problem.
> 
> 	return ++num_tc;
> 
> There's nothing wrong with the original code
> unless this is a bugfix which should be documented
> better than "better return values".

Agreed, this style of coding is asking for a bug.

If you want to return "num_tc PLUS ONE" just say that:

	return num_tc + 1;

Why even use pre/post increment when the variable has no other
use than as a return value?

  reply	other threads:[~2013-09-24 14:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24  9:45 [net 0/6][pull request] Intel Wired LAN Driver Updates Jeff Kirsher
2013-09-24  9:45 ` [net 1/6] igb: Fix ethtool loopback test for 82580 copper Jeff Kirsher
2013-09-24  9:45 ` [net 2/6] i40e: use common failure flow Jeff Kirsher
2013-09-24  9:45 ` [net 3/6] i40e: small clean ups from review Jeff Kirsher
2013-09-24  9:45 ` [net 4/6] i40e: convert ret to aq_ret Jeff Kirsher
2013-09-24  9:45 ` [net 5/6] i40e: better return values Jeff Kirsher
2013-09-24 11:34   ` Joe Perches
2013-09-24 14:12     ` David Miller [this message]
2013-09-24 19:09       ` Jesse Brandeburg
2013-09-24  9:45 ` [net 6/6] i40e: clean up coccicheck reported errors Jeff Kirsher

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=20130924.101231.1193830264265403478.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=gospo@redhat.com \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=joe@perches.com \
    --cc=netdev@vger.kernel.org \
    --cc=sassmann@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).