__dev_alloc_name(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ __dev_alloc_name(9) β€” Kernel API Manual ✨

ok so this page lives in the Kernel API Manual (that's the manual name bestie, section 9), and it's literally the whole lore on how a network device gets its name. sit down, hydrate, let's go πŸ’…


🌸 NAME 🌸

__dev_alloc_name β€” allocate a name for a device

like, you hand it a format and it finds you a name. that's the entire job. iconic honestly πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

int __dev_alloc_name (struct net *net , const char *name , char *res );

that's it. three args. no cap.


πŸ’– ARGUMENTS πŸ’–

  • net β€” the network namespace you want to allocate the device name in. that's the vibe check zone for the name.
  • name β€” the name format string. yes, a format string, we'll get to that.
  • res β€” the result name string. where the winning name ends up πŸ’«

🌈 DESCRIPTION 🌈

okay so picture this: you pass in a format string β€” the page's example is "ltd" β€” and it goes off and tries to find a suitable id for it. that's the whole mission.

it scans the list of devices to build up a free map, and then it chooses the first empty slot it finds. first come, first served, main character energy πŸ‘‘

⚠️ bestie listen. the caller must hold the dev_base or rtnl lock while allocating the name and adding the device, or you get duplicates. and nobody wants duplicates. that's the whole point. do not skip the lock, fr fr 😭

also there's a ceiling: it's limited to bits_per_byte * page size devices β€” which is ie 32K on most platforms. so it's not infinite, she has a limit πŸ’€

and what does it give back? it returns the number of the unit assigned or a negative errno code. so if you get a negative back, that's not a unit number bestie, that's a problem πŸ™ˆ


🧚 SEE ALSO 🧚

the whole net/core crew, all of them, no skips, we're doing attendance πŸ“‹ (kernel file ./net/core/dev.c):


and that's the page bestie!! 🫢 this one shipped from the kernel file ./net/core and it's dated October 2026 β€” so yeah, she's fresh, she's current, she's booked and busy ✨ mwah πŸ’œ

πŸ“¦ where this page comes from