From: zhenwei pi <pizhenwei@bytedance.com>
To: Markus Elfring <Markus.Elfring@web.de>,
Gonglei <arei.gonglei@huawei.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
linux-crypto@vger.kernel.org,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Nathan Chancellor" <nathan@kernel.org>,
virtualization@lists.linux.dev,
"lei he" <helei.sig11@bytedance.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"Eugenio Pérez" <eperezma@redhat.com>,
"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] crypto: virtio/akcipher - Move a pointer assignment in virtio_crypto_rsa_set_key()
Date: Sat, 12 Oct 2024 16:24:01 +0800 [thread overview]
Message-ID: <870327e4-2391-4f42-82ad-2d9593a70ebe@bytedance.com> (raw)
In-Reply-To: <80b91321-138c-41de-95c7-47c3be07fe76@web.de>
On 10/12/24 16:06, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 12 Oct 2024 09:51:58 +0200
>
> Move the reset of the data structure member “n” to a null pointer
> into an if branch so that this assignment will be performed only after
> a key parsing failure.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/crypto/virtio/virtio_crypto_akcipher_algs.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> index 48fee07b7e51..56557d4778b0 100644
> --- a/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> +++ b/drivers/crypto/virtio/virtio_crypto_akcipher_algs.c
> @@ -355,7 +355,6 @@ static int virtio_crypto_rsa_set_key(struct crypto_akcipher *tfm,
>
> /* mpi_free will test n, just free it. */
> mpi_free(rsa_ctx->n);
> - rsa_ctx->n = NULL;
>
> if (private) {
> keytype = VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE;
> @@ -365,8 +364,10 @@ static int virtio_crypto_rsa_set_key(struct crypto_akcipher *tfm,
> ret = rsa_parse_pub_key(&rsa_key, key, keylen);
> }
>
> - if (ret)
> + if (ret) {
> + rsa_ctx->n = NULL;
> return ret;
> + }
>
> rsa_ctx->n = mpi_read_raw_data(rsa_key.n, rsa_key.n_sz);
> if (!rsa_ctx->n)
> --
Hi,
This change only reduces a single assignment on a key parsing failure,
however it breaks the original "free a pointer, and set it to NULL".
I prefer the original style.
Lei, what's your opinion?
> 2.46.1
>
prev parent reply other threads:[~2024-10-12 8:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-12 8:06 Markus Elfring
2024-10-12 8:24 ` zhenwei pi [this message]
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=870327e4-2391-4f42-82ad-2d9593a70ebe@bytedance.com \
--to=pizhenwei@bytedance.com \
--cc=Markus.Elfring@web.de \
--cc=arei.gonglei@huawei.com \
--cc=davem@davemloft.net \
--cc=eperezma@redhat.com \
--cc=helei.sig11@bytedance.com \
--cc=herbert@gondor.apana.org.au \
--cc=jasowang@redhat.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=nathan@kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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
all inboxes | Powered by JetHome®