device_rename(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… device_rename β€” Kernel API Manual ✨

okay so bestie, welcome to the device_rename(9) page from the Kernel API Manual, and buckle up because this one is a whole journey 🎒


🌸 NAME 🌸

device_rename β€” renames a device 🏷️✨


πŸŽ€ SYNOPSIS πŸŽ€

int device_rename (struct device *dev , const char *new_name );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • dev β€” the pointer to the struct device you wanna rename, like giving your pet a new name but the pet is a kernel object 🐾
  • new_name β€” the new name of the device, aka the glow-up ✨

πŸ’– DESCRIPTION πŸ’–

so here's the thing: it is the responsibility of the caller to provide mutual exclusion between two different calls of device_rename on the same device. that's the whole job, no cap. you gotta do it so that new_name is actually valid and won't conflict with other devices 🫢

like, the function is not gonna lock anything for you. that's on you. periodt πŸ’…


πŸ”₯ NOTE πŸ”₯

ngl, some subsystems β€” networking and infiniband β€” use this function, and there are no immediate plans for this to change. so we cannot assume or require that this function not be called at all πŸ™ˆ

but β€” and this is a big but β€” if you're writing new code, do not call this function. 🚨

the following text from Kay Sievers offers some insight, and it is honestly iconic in a tragic way 😭:

renaming devices is racy at many levels. symlinks and other stuff are not replaced atomically, and you get a "move" uevent, but it's not easy to connect the event to the old and new device. device nodes are not renamed at all β€” there isn't even support for that in the kernel now πŸ’€

in the meantime, during renaming, your target name might be taken by another driver, creating conflicts. or the old name is taken directly after you renamed it β€” then you get events for the same DEVPATH, before you even see the "move" event. it's just a mess, and nothing new should ever rely on kernel device renaming. besides that, it's not even implemented now for other things than (driver-core wise very simple) network devices πŸ™ƒ

so what's the move instead? make up a "real" name in the driver before you register anything, or add some other attributes for userspace to find the device, or use udev to add symlinks β€” but never rename kernel devices later, it's a complete mess. we don't even want to get into that and try to implement the missing pieces in the core. we really have other pieces to fix in the driver core mess. :) πŸ’€πŸ’…


🌈 SEE ALSO 🌈

Kernel file ./drivers/base/core.c β€” and bestie, this list is long, so here we go πŸ‘‘


okay that's the whole page bestie, we ate and left zero crumbs πŸ“πŸ’œ this came from ./drivers/base, dated October 2026 β€” mwah, go touch some device nodes (but maybe don't rename them) 🧚✨

πŸ“¦ where this page comes from