Re: [PATCH net v2] libceph: Make the arguments const as per the TODO

From: Simon Horman
Date: Mon Aug 12 2024 - 11:46:35 EST


On Mon, Aug 12, 2024 at 02:25:09AM +0530, Abhinav Jain wrote:
> net/ceph/crypto.c:
> Modify arguments to const in ceph_crypto_key_decode().
> Modify ceph_key_preparse() and ceph_crypto_key_unarmor()
> in accordance with the changes.
>
> net/ceph/crypto.h:
> Add changes in the prototype of ceph_crypto_key_decode().
>
> net/ceph/auth_x.c:
> Modify the arguments to function ceph_crypto_key_decode()
> being called in the function process_one_ticket().

Hi,

I think that the subject and patch description need to be reworked.
We can see easily enough from the code what is being done.
But why?

>
> v1:
> lore.kernel.org/all/20240811193645.1082042-1-jain.abhinav177@xxxxxxxxx
>
> Changes since v1:
> - Incorrect changes made in v1 fixed.
> - Found the other files where the change needed to be made.
>
> Signed-off-by: Abhinav Jain <jain.abhinav177@xxxxxxxxx>

Please take some time before posting the next revision of this patch.

Please do run checkpatch.pl --strict --codespell
and, within reason, correct the issues it flags.

Please make sure that allmodconfig builds compile.
At least on x86_64.

...

> diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c

...

> @@ -123,7 +124,7 @@ int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *inkey)
> }
>
> p = buf;
> - ret = ceph_crypto_key_decode(key, &p, p + blen);
> + ret = ceph_crypto_key_decode(key, &p, (const void *)((const char *)p + blen));

It is usually not necessary to implicitly cast a pointer to (void *).
Also, while it mat address a compiler warning, it's not claear to me how
this is related to the const change that is the subject of this patch.

> kfree(buf);
> if (ret)
> return ret;

...

> @@ -311,9 +312,9 @@ static int ceph_key_preparse(struct key_preparsed_payload *prep)
> if (!ckey)
> goto err;
>
> - /* TODO ceph_crypto_key_decode should really take const input */
> - p = (void *)prep->data;
> - ret = ceph_crypto_key_decode(ckey, &p, (char*)prep->data+datalen);
> + p = prep->data;
> + ret = ceph_crypto_key_decode(ckey, &p, \
> + (const void *)((const char *)prep->data + datalen));

I don't think you need the cast to void * here either.

> if (ret < 0)
> goto err_ckey;
>

...