All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Colin King <colin.king@canonical.com>
Cc: Jiri Pirko <jiri@mellanox.com>,
	Ido Schimmel <idosch@mellanox.com>,
	"David S . Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
Date: Fri, 03 Apr 2020 08:46:24 +0000	[thread overview]
Message-ID: <20200403084624.GA2001@kadam> (raw)
In-Reply-To: <20200402144851.565983-1-colin.king@canonical.com>

On Thu, Apr 02, 2020 at 03:48:51PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> index 9096ffd89e50..fbf714d027d8 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> @@ -643,7 +643,7 @@ static int mlxsw_sp_trap_policer_bs(u64 burst, u8 *p_burst_size,
>  {
>  	int bs = fls64(burst) - 1;
>  
> -	if (burst != (1 << bs)) {
> +	if (burst != (BIT_ULL(bs))) {

Please delete the extra parentheses.

	if (burst != BIT_ULL(bs)) {

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Colin King <colin.king@canonical.com>
Cc: Jiri Pirko <jiri@mellanox.com>,
	Ido Schimmel <idosch@mellanox.com>,
	"David S . Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift
Date: Fri, 3 Apr 2020 11:46:24 +0300	[thread overview]
Message-ID: <20200403084624.GA2001@kadam> (raw)
In-Reply-To: <20200402144851.565983-1-colin.king@canonical.com>

On Thu, Apr 02, 2020 at 03:48:51PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1 is evaluated using 32-bit
> arithmetic and then used in an expression that expects a 64-bit
> value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the
> overflow.
> 
> Addresses-Coverity: ("Unintentional integer overflow")
> Fixes: 13f2e64b94ea ("mlxsw: spectrum_trap: Add devlink-trap policer support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> index 9096ffd89e50..fbf714d027d8 100644
> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_trap.c
> @@ -643,7 +643,7 @@ static int mlxsw_sp_trap_policer_bs(u64 burst, u8 *p_burst_size,
>  {
>  	int bs = fls64(burst) - 1;
>  
> -	if (burst != (1 << bs)) {
> +	if (burst != (BIT_ULL(bs))) {

Please delete the extra parentheses.

	if (burst != BIT_ULL(bs)) {

regards,
dan carpenter


  parent reply	other threads:[~2020-04-03  8:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-02 14:48 [PATCH][next] mlxsw: spectrum_trap: fix unintention integer overflow on left shift Colin King
2020-04-02 14:48 ` Colin King
2020-04-02 15:48 ` Ido Schimmel
2020-04-02 15:48   ` Ido Schimmel
2020-04-03  1:00 ` David Miller
2020-04-03  1:00   ` David Miller
2020-04-03  8:46 ` Dan Carpenter [this message]
2020-04-03  8:46   ` Dan Carpenter
2020-04-03 16:05 ` [PATCH][next] mlxsw: spectrum_trap: Fix unintentional " Markus Elfring
2020-04-03 16:05   ` Markus Elfring

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=20200403084624.GA2001@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=idosch@mellanox.com \
    --cc=jiri@mellanox.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.