kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Typecasting a void pointer to unsigned long in zsmalloc.c
@ 2025-01-23 15:52 Sotir Danailov
  2025-01-23 15:59 ` Greg KH
  0 siblings, 1 reply; 23+ messages in thread
From: Sotir Danailov @ 2025-01-23 15:52 UTC (permalink / raw)
  To: kernelnewbies

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@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 23+ messages in thread
[parent not found: <mailman.1.1737651601.26911.kernelnewbies@kernelnewbies.org>]

end of thread, other threads:[~2025-01-28 10:24 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-23 15:52 Typecasting a void pointer to unsigned long in zsmalloc.c Sotir Danailov
2025-01-23 15:59 ` Greg KH
2025-01-23 16:27   ` Sotir Danailov
2025-01-23 17:00     ` Greg KH
2025-01-23 17:05       ` Sotir Danailov
2025-01-23 17:40         ` Leam Hall
2025-01-23 18:30           ` Sotir Danailov
2025-01-23 19:54             ` Leam Hall
2025-01-23 20:48               ` Sotir Danailov
2025-01-23 21:09                 ` Costa Shulyupin
2025-01-24  5:13                   ` Greg KH
2025-01-24 21:45                     ` Sotir Danailov
2025-01-26 23:29                       ` Leam Hall
2025-01-27 10:39                         ` Sotir Danailov
2025-01-27 13:48                           ` Leam Hall
2025-01-28  8:45                             ` Sotir Danailov
2025-01-28  8:58                               ` Costa Shulyupin
2025-01-28  9:14                                 ` Sotir Danailov
2025-01-28  9:24                           ` Sotir Danailov
2025-01-28 10:23                             ` Leam Hall
2025-01-23 18:44     ` jim.cromie
     [not found] <mailman.1.1737651601.26911.kernelnewbies@kernelnewbies.org>
2025-01-23 17:58 ` Alex Hogen
2025-01-23 18:23   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).