Typecasting a void pointer to unsigned long in zsmalloc.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



While looking through the zsmalloc.c file I stumbled upon something.

On the following line, in the zs_malloc() function:
handle = cache_alloc_handle(pool, gfp);
https://elixir.bootlin.com/linux/v6.13-rc3/source/mm/zsmalloc.c#L1356

the handle is a result of a typecast from a void pointer to an unsigned long.

return (unsigned long)kmem_cache_alloc(...);
https://elixir.bootlin.com/linux/v6.13-rc3/source/mm/zsmalloc.c#L333

What's the guarantee that an unsigned long can hold the data
from the void pointer? Is this safe to do? Shouldn't there be a special type
for doing this type of conversion?

I understand the reason for not using the void pointer directly and why
they need a "handle" instead, but I'm just a bit confused
by the method that has been chosen here.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]

  Powered by Linux