diff mbox series

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

Message ID 20240811205509.1089027-1-jain.abhinav177@gmail.com
State New
Headers show
Series [net,v2] libceph: Make the arguments const as per the TODO | expand

Commit Message

Abhinav Jain Aug. 11, 2024, 8:55 p.m. UTC
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().

v1:
lore.kernel.org/all/20240811193645.1082042-1-jain.abhinav177@gmail.com

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@gmail.com>
---
 net/ceph/auth_x.c |  4 +++-
 net/ceph/crypto.c | 15 ++++++++-------
 net/ceph/crypto.h |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

Comments

kernel test robot Aug. 12, 2024, 7:09 a.m. UTC | #1
Hi Abhinav,

kernel test robot noticed the following build errors:

[auto build test ERROR on net/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Abhinav-Jain/libceph-Make-the-arguments-const-as-per-the-TODO/20240812-045647
base:   net/main
patch link:    https://lore.kernel.org/r/20240811205509.1089027-1-jain.abhinav177%40gmail.com
patch subject: [PATCH net v2] libceph: Make the arguments const as per the TODO
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20240812/202408121452.qS7GNcws-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240812/202408121452.qS7GNcws-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408121452.qS7GNcws-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/array_size.h:5,
                    from include/linux/string.h:6,
                    from include/linux/ceph/ceph_debug.h:7,
                    from net/ceph/crypto.c:3:
   net/ceph/crypto.c: In function 'ceph_crypto_key_decode':
>> net/ceph/crypto.c:93:26: error: passing argument 1 of 'ceph_has_room' from incompatible pointer type [-Werror=incompatible-pointer-types]
      93 |         ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
         |                          ^
         |                          |
         |                          const void **
   include/linux/compiler.h:76:45: note: in definition of macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   net/ceph/crypto.c:93:9: note: in expansion of macro 'ceph_decode_need'
      93 |         ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
         |         ^~~~~~~~~~~~~~~~
   In file included from net/ceph/crypto.c:16:
   include/linux/ceph/decode.h:52:41: note: expected 'void **' but argument is of type 'const void **'
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                  ~~~~~~~^
   net/ceph/crypto.c:93:29: warning: passing argument 2 of 'ceph_has_room' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      93 |         ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
         |                             ^~~
   include/linux/compiler.h:76:45: note: in definition of macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   net/ceph/crypto.c:93:9: note: in expansion of macro 'ceph_decode_need'
      93 |         ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
         |         ^~~~~~~~~~~~~~~~
   include/linux/ceph/decode.h:52:50: note: expected 'void *' but argument is of type 'const void *'
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                            ~~~~~~^~~
>> net/ceph/crypto.c:94:36: error: passing argument 1 of 'ceph_decode_16' from incompatible pointer type [-Werror=incompatible-pointer-types]
      94 |         key->type = ceph_decode_16(p);
         |                                    ^
         |                                    |
         |                                    const void **
   include/linux/ceph/decode.h:31:41: note: expected 'void **' but argument is of type 'const void **'
      31 | static inline u16 ceph_decode_16(void **p)
         |                                  ~~~~~~~^
>> net/ceph/crypto.c:95:26: error: passing argument 1 of 'ceph_decode_copy' from incompatible pointer type [-Werror=incompatible-pointer-types]
      95 |         ceph_decode_copy(p, &key->created, sizeof(key->created));
         |                          ^
         |                          |
         |                          const void **
   include/linux/ceph/decode.h:43:44: note: expected 'void **' but argument is of type 'const void **'
      43 | static inline void ceph_decode_copy(void **p, void *pv, size_t n)
         |                                     ~~~~~~~^
   net/ceph/crypto.c:96:35: error: passing argument 1 of 'ceph_decode_16' from incompatible pointer type [-Werror=incompatible-pointer-types]
      96 |         key->len = ceph_decode_16(p);
         |                                   ^
         |                                   |
         |                                   const void **
   include/linux/ceph/decode.h:31:41: note: expected 'void **' but argument is of type 'const void **'
      31 | static inline u16 ceph_decode_16(void **p)
         |                                  ~~~~~~~^
   net/ceph/crypto.c:97:26: error: passing argument 1 of 'ceph_has_room' from incompatible pointer type [-Werror=incompatible-pointer-types]
      97 |         ceph_decode_need(p, end, key->len, bad);
         |                          ^
         |                          |
         |                          const void **
   include/linux/compiler.h:76:45: note: in definition of macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   net/ceph/crypto.c:97:9: note: in expansion of macro 'ceph_decode_need'
      97 |         ceph_decode_need(p, end, key->len, bad);
         |         ^~~~~~~~~~~~~~~~
   include/linux/ceph/decode.h:52:41: note: expected 'void **' but argument is of type 'const void **'
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                  ~~~~~~~^
   net/ceph/crypto.c:97:29: warning: passing argument 2 of 'ceph_has_room' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      97 |         ceph_decode_need(p, end, key->len, bad);
         |                             ^~~
   include/linux/compiler.h:76:45: note: in definition of macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   net/ceph/crypto.c:97:9: note: in expansion of macro 'ceph_decode_need'
      97 |         ceph_decode_need(p, end, key->len, bad);
         |         ^~~~~~~~~~~~~~~~
   include/linux/ceph/decode.h:52:50: note: expected 'void *' but argument is of type 'const void *'
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                            ~~~~~~^~~
   net/ceph/crypto.c:98:31: warning: passing argument 2 of 'set_secret' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      98 |         ret = set_secret(key, *p);
         |                               ^~
   net/ceph/crypto.c:23:58: note: expected 'void *' but argument is of type 'const void *'
      23 | static int set_secret(struct ceph_crypto_key *key, void *buf)
         |                                                    ~~~~~~^~~
   net/ceph/crypto.c:99:26: warning: passing argument 1 of 'memzero_explicit' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      99 |         memzero_explicit(*p, key->len);
         |                          ^~
   include/linux/string.h:356:43: note: expected 'void *' but argument is of type 'const void *'
     356 | static inline void memzero_explicit(void *s, size_t count)
         |                                     ~~~~~~^
   during RTL pass: mach
   net/ceph/crypto.c: In function 'ceph_crypto_key_unarmor':
   net/ceph/crypto.c:134:1: internal compiler error: in arc_ifcvt, at config/arc/arc.cc:9703
     134 | }
         | ^
   0x5b78c1 arc_ifcvt
   	/tmp/build-crosstools-gcc-13.2.0-binutils-2.41/gcc/gcc-13.2.0/gcc/config/arc/arc.cc:9703
   0xe431b4 arc_reorg
   	/tmp/build-crosstools-gcc-13.2.0-binutils-2.41/gcc/gcc-13.2.0/gcc/config/arc/arc.cc:8552
   0xaed299 execute
   	/tmp/build-crosstools-gcc-13.2.0-binutils-2.41/gcc/gcc-13.2.0/gcc/reorg.cc:3927
   Please submit a full bug report, with preprocessed source (by using -freport-bug).
   Please include the complete backtrace with any bug report.
   See <https://gcc.gnu.org/bugs/> for instructions.


vim +/ceph_has_room +93 net/ceph/crypto.c

8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   88  
19c7b44529ef1b net/ceph/crypto.c Abhinav Jain 2024-08-12   89  int ceph_crypto_key_decode(struct ceph_crypto_key *key, const void **p, const void *end)
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   90  {
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02   91  	int ret;
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02   92  
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  @93  	ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  @94  	key->type = ceph_decode_16(p);
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  @95  	ceph_decode_copy(p, &key->created, sizeof(key->created));
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   96  	key->len = ceph_decode_16(p);
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   97  	ceph_decode_need(p, end, key->len, bad);
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02   98  	ret = set_secret(key, *p);
10f42b3e648377 net/ceph/crypto.c Ilya Dryomov 2020-12-22   99  	memzero_explicit(*p, key->len);
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02  100  	*p += key->len;
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02  101  	return ret;
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  102  
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  103  bad:
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  104  	dout("failed to decode crypto key\n");
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  105  	return -EINVAL;
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  106  }
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  107
kernel test robot Aug. 12, 2024, 3:26 p.m. UTC | #2
Hi Abhinav,

kernel test robot noticed the following build errors:

[auto build test ERROR on net/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Abhinav-Jain/libceph-Make-the-arguments-const-as-per-the-TODO/20240812-045647
base:   net/main
patch link:    https://lore.kernel.org/r/20240811205509.1089027-1-jain.abhinav177%40gmail.com
patch subject: [PATCH net v2] libceph: Make the arguments const as per the TODO
config: i386-buildonly-randconfig-002-20240812 (https://download.01.org/0day-ci/archive/20240812/202408121938.QL7KtnzW-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240812/202408121938.QL7KtnzW-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408121938.QL7KtnzW-lkp@intel.com/

All errors (new ones prefixed by >>):

>> net/ceph/crypto.c:93:19: error: passing 'const void **' to parameter of type 'void **' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      93 |         ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
         |                          ^
   include/linux/ceph/decode.h:59:29: note: expanded from macro 'ceph_decode_need'
      59 |                 if (!likely(ceph_has_room(p, end, n)))          \
         |                                           ^
   include/linux/compiler.h:76:40: note: expanded from macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   include/linux/ceph/decode.h:52:41: note: passing argument to parameter 'p' here
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                         ^
>> net/ceph/crypto.c:93:22: error: passing 'const void *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      93 |         ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
         |                             ^~~
   include/linux/ceph/decode.h:59:32: note: expanded from macro 'ceph_decode_need'
      59 |                 if (!likely(ceph_has_room(p, end, n)))          \
         |                                              ^~~
   include/linux/compiler.h:76:40: note: expanded from macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   include/linux/ceph/decode.h:52:50: note: passing argument to parameter 'end' here
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                                  ^
   net/ceph/crypto.c:94:29: error: passing 'const void **' to parameter of type 'void **' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      94 |         key->type = ceph_decode_16(p);
         |                                    ^
   include/linux/ceph/decode.h:31:41: note: passing argument to parameter 'p' here
      31 | static inline u16 ceph_decode_16(void **p)
         |                                         ^
   net/ceph/crypto.c:95:19: error: passing 'const void **' to parameter of type 'void **' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      95 |         ceph_decode_copy(p, &key->created, sizeof(key->created));
         |                          ^
   include/linux/ceph/decode.h:43:44: note: passing argument to parameter 'p' here
      43 | static inline void ceph_decode_copy(void **p, void *pv, size_t n)
         |                                            ^
   net/ceph/crypto.c:96:28: error: passing 'const void **' to parameter of type 'void **' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      96 |         key->len = ceph_decode_16(p);
         |                                   ^
   include/linux/ceph/decode.h:31:41: note: passing argument to parameter 'p' here
      31 | static inline u16 ceph_decode_16(void **p)
         |                                         ^
   net/ceph/crypto.c:97:19: error: passing 'const void **' to parameter of type 'void **' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      97 |         ceph_decode_need(p, end, key->len, bad);
         |                          ^
   include/linux/ceph/decode.h:59:29: note: expanded from macro 'ceph_decode_need'
      59 |                 if (!likely(ceph_has_room(p, end, n)))          \
         |                                           ^
   include/linux/compiler.h:76:40: note: expanded from macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   include/linux/ceph/decode.h:52:41: note: passing argument to parameter 'p' here
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                         ^
   net/ceph/crypto.c:97:22: error: passing 'const void *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      97 |         ceph_decode_need(p, end, key->len, bad);
         |                             ^~~
   include/linux/ceph/decode.h:59:32: note: expanded from macro 'ceph_decode_need'
      59 |                 if (!likely(ceph_has_room(p, end, n)))          \
         |                                              ^~~
   include/linux/compiler.h:76:40: note: expanded from macro 'likely'
      76 | # define likely(x)      __builtin_expect(!!(x), 1)
         |                                             ^
   include/linux/ceph/decode.h:52:50: note: passing argument to parameter 'end' here
      52 | static inline bool ceph_has_room(void **p, void *end, size_t n)
         |                                                  ^
   net/ceph/crypto.c:98:24: error: passing 'const void *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      98 |         ret = set_secret(key, *p);
         |                               ^~
   net/ceph/crypto.c:23:58: note: passing argument to parameter 'buf' here
      23 | static int set_secret(struct ceph_crypto_key *key, void *buf)
         |                                                          ^
   net/ceph/crypto.c:99:19: error: passing 'const void *' to parameter of type 'void *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      99 |         memzero_explicit(*p, key->len);
         |                          ^~
   include/linux/string.h:356:43: note: passing argument to parameter 's' here
     356 | static inline void memzero_explicit(void *s, size_t count)
         |                                           ^
   9 errors generated.


vim +93 net/ceph/crypto.c

8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   88  
19c7b44529ef1b net/ceph/crypto.c Abhinav Jain 2024-08-12   89  int ceph_crypto_key_decode(struct ceph_crypto_key *key, const void **p, const void *end)
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   90  {
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02   91  	int ret;
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02   92  
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  @93  	ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   94  	key->type = ceph_decode_16(p);
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   95  	ceph_decode_copy(p, &key->created, sizeof(key->created));
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   96  	key->len = ceph_decode_16(p);
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02   97  	ceph_decode_need(p, end, key->len, bad);
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02   98  	ret = set_secret(key, *p);
10f42b3e648377 net/ceph/crypto.c Ilya Dryomov 2020-12-22   99  	memzero_explicit(*p, key->len);
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02  100  	*p += key->len;
7af3ea189a9a13 net/ceph/crypto.c Ilya Dryomov 2016-12-02  101  	return ret;
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  102  
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  103  bad:
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  104  	dout("failed to decode crypto key\n");
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  105  	return -EINVAL;
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  106  }
8b6e4f2d8b21c2 fs/ceph/crypto.c  Sage Weil    2010-02-02  107
Simon Horman Aug. 12, 2024, 3:46 p.m. UTC | #3
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@gmail.com
> 
> 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@gmail.com>

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;
>  

...
diff mbox series

Patch

diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c
index b71b1635916e..81272603f981 100644
--- a/net/ceph/auth_x.c
+++ b/net/ceph/auth_x.c
@@ -204,7 +204,9 @@  static int process_one_ticket(struct ceph_auth_client *ac,
 	if (tkt_struct_v != 1)
 		goto bad;
 
-	ret = ceph_crypto_key_decode(&new_session_key, &dp, dend);
+	ret = ceph_crypto_key_decode(&new_session_key, \
+		(const void **)&dp, (const void *)dend);
+
 	if (ret)
 		goto out;
 
diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c
index 051d22c0e4ad..905b80d738b1 100644
--- a/net/ceph/crypto.c
+++ b/net/ceph/crypto.c
@@ -86,7 +86,7 @@  int ceph_crypto_key_encode(struct ceph_crypto_key *key, void **p, void *end)
 	return 0;
 }
 
-int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end)
+int ceph_crypto_key_decode(struct ceph_crypto_key *key, const void **p, const void *end)
 {
 	int ret;
 
@@ -109,7 +109,8 @@  int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *inkey)
 {
 	int inlen = strlen(inkey);
 	int blen = inlen * 3 / 4;
-	void *buf, *p;
+	void *buf;
+	const void *p;
 	int ret;
 
 	dout("crypto_key_unarmor %s\n", inkey);
@@ -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));
 	kfree(buf);
 	if (ret)
 		return ret;
@@ -300,7 +301,7 @@  static int ceph_key_preparse(struct key_preparsed_payload *prep)
 	struct ceph_crypto_key *ckey;
 	size_t datalen = prep->datalen;
 	int ret;
-	void *p;
+	const void *p;
 
 	ret = -EINVAL;
 	if (datalen <= 0 || datalen > 32767 || !prep->data)
@@ -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));
 	if (ret < 0)
 		goto err_ckey;
 
diff --git a/net/ceph/crypto.h b/net/ceph/crypto.h
index 13bd526349fa..ba57376fa635 100644
--- a/net/ceph/crypto.h
+++ b/net/ceph/crypto.h
@@ -22,7 +22,7 @@  struct ceph_crypto_key {
 int ceph_crypto_key_clone(struct ceph_crypto_key *dst,
 			  const struct ceph_crypto_key *src);
 int ceph_crypto_key_encode(struct ceph_crypto_key *key, void **p, void *end);
-int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end);
+int ceph_crypto_key_decode(struct ceph_crypto_key *key, const void **p, const void *end);
 int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *in);
 void ceph_crypto_key_destroy(struct ceph_crypto_key *key);