public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Gilad Ben-Yossef <gilad@benyossef.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	driverdev-devel@linuxdriverproject.org,
	linux-crypto@vger.kernel.org, Ofir Drang <ofir.drang@arm.com>
Subject: Re: [PATCH 7/8] staging: ccree: remove compare to none zero
Date: Tue, 7 Nov 2017 13:52:39 +0300	[thread overview]
Message-ID: <20171107105239.ifmkzkf5c2xjacx4@mwanda> (raw)
In-Reply-To: <1510047606-5589-8-git-send-email-gilad@benyossef.com>

On Tue, Nov 07, 2017 at 09:40:03AM +0000, Gilad Ben-Yossef wrote:
> diff --git a/drivers/staging/ccree/ssi_aead.c b/drivers/staging/ccree/ssi_aead.c
> index f1a3976..e9d03ee 100644
> --- a/drivers/staging/ccree/ssi_aead.c
> +++ b/drivers/staging/ccree/ssi_aead.c
> @@ -240,7 +240,7 @@ static void ssi_aead_complete(struct device *dev, void *ssi_req, void __iomem *c
>  
>  	if (areq_ctx->gen_ctx.op_type == DRV_CRYPTO_DIRECTION_DECRYPT) {
>  		if (memcmp(areq_ctx->mac_buf, areq_ctx->icv_virt_addr,
> -			   ctx->authsize) != 0) {
> +			   ctx->authsize)) {

Keep the != for *cmp functions.  It makes it way more readable.  The
idiom is:

	if (memcmp(a, b, size) != 0)  <-- this means a != b
	if (memcmp(a, b, size) < 0)   <-- this means a < b
	if (memcmp(a, b, size) == 0)  <-- this means a == b

>  			dev_dbg(dev, "Payload authentication failure, (auth-size=%d, cipher=%d)\n",
>  				ctx->authsize, ctx->cipher_mode);
>  			/* In case of payload authentication failure, MUST NOT
> @@ -458,7 +458,7 @@ ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keyl
>  		hashmode = DRV_HASH_HW_SHA256;
>  	}
>  
> -	if (likely(keylen != 0)) {
> +	if (likely(keylen)) {

You can keep the zero here as well if you want.  keylen is a number and
zero is a number.  If you want to remove it that's fine too.

>  		key_dma_addr = dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE);
>  		if (unlikely(dma_mapping_error(dev, key_dma_addr))) {
>  			dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n",
> @@ -517,7 +517,7 @@ ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keyl
>  				      keylen, NS_BIT, 0);
>  			idx++;
>  
> -			if ((blocksize - keylen) != 0) {
> +			if (blocksize - keylen) {

Same.  Numbers can be compared to zero and it's fine.

>  				hw_desc_init(&desc[idx]);
>  				set_din_const(&desc[idx], 0,
>  					      (blocksize - keylen));
> @@ -539,10 +539,10 @@ ssi_get_plain_hmac_key(struct crypto_aead *tfm, const u8 *key, unsigned int keyl
>  	}
>  
>  	rc = send_request(ctx->drvdata, &ssi_req, desc, idx, 0);
> -	if (unlikely(rc != 0))
> +	if (unlikely(rc))

Where-as for these ones "rc" is not a number we can use for math so the
!= 0 is just a double negative and slightly confusing, so removing it
is the right thing.

regards,
dan carpenter

  reply	other threads:[~2017-11-07 10:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-07  9:39 [PATCH 0/8] staging: ccree: fixes and cleanups Gilad Ben-Yossef
2017-11-07  9:39 ` [PATCH 1/8] staging: ccree: fix leak of import() after init() Gilad Ben-Yossef
2017-11-07  9:39 ` [PATCH 2/8] staging: ccree: use more readable func names Gilad Ben-Yossef
2017-11-07 10:30   ` Dan Carpenter
2017-11-09  6:26     ` Gilad Ben-Yossef
2017-11-07  9:39 ` [PATCH 3/8] staging: ccree: simplify AEAD using local var Gilad Ben-Yossef
2017-11-07 10:35   ` Dan Carpenter
2017-11-07  9:40 ` [PATCH 4/8] staging: ccree: simplify buf mgr using local vars Gilad Ben-Yossef
2017-11-07  9:40 ` [PATCH 5/8] staging: ccree: fold common code into function Gilad Ben-Yossef
2017-11-07 10:40   ` Dan Carpenter
2017-11-07  9:40 ` [PATCH 6/8] staging: ccree: simplify pm manager using local var Gilad Ben-Yossef
2017-11-07 10:43   ` Dan Carpenter
2017-11-09  6:27     ` Gilad Ben-Yossef
2017-11-09 12:54       ` Dan Carpenter
2017-11-07  9:40 ` [PATCH 7/8] staging: ccree: remove compare to none zero Gilad Ben-Yossef
2017-11-07 10:52   ` Dan Carpenter [this message]
2017-11-07  9:40 ` [PATCH 8/8] staging: ccree: remove braces for single statement Gilad Ben-Yossef

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=20171107105239.ifmkzkf5c2xjacx4@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gilad@benyossef.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ofir.drang@arm.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