__starget_for_each_device(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __starget_for_each_device β€” the "walk every device on a target, no locks taken" helper

okay so real talk, this one lives in the Kernel API Manual and it's the unlocked sibling of the locked loop you probably want. bestie, read the NOTE before you commit, i'm begging 🫢


✨ NAME ✨

__starget_for_each_device β€” a helper to walk all devices of a target, and it is (UNLOCKED) πŸ‘€

Like. It doesn't lock anything for you. That's the whole personality. πŸ’€


🌸 SYNOPSIS 🌸

void __starget_for_each_device (struct scsi_target *starget , void *data
, void (*fn)(struct scsi_device *, void *) );

the way that signature is literally just target, blob of data, callback, and then vibes πŸ¦‹


πŸŽ€ ARGUMENTS πŸŽ€

  • starget β€” the target whose devices we want to iterate over. this is the main character of the loop πŸ’…
  • data β€” a parameter for callback fn. it just gets passed straight through, no questions asked πŸ“
  • fn β€” the callback function that is invoked for each device. it's giving you supply the behaviour, i supply the iteration ✨

πŸ’– DESCRIPTION πŸ’–

so what it does: this traverses over each device of starget, calling your fn on every single one. slay. 🌈

but here's the iconic part β€” it does not take a reference on the scsi_device. not one. so the whole loop must be protected by shost->host_lock. yes, the entire loop. no cap. πŸ”₯

⚠️ no reference taken + unlocked traversal means you own the locking. if you don't hold shost->host_lock around the entire loop, that's on you, and the kernel will not be sending you a cute little warning first 😭

πŸ‘‘ NOTE πŸ‘‘

the only reason why drivers would want to use this is because they need to access the device list in irq context. like, that's the one legit use case, periodt. πŸ’«

otherwise, bestie, you really want to use starget_for_each_device instead. fr fr. the locked one. the safe one. the one that doesn't make you hold host_lock manually while stress-crying into your dmesg πŸ™ˆ


🧚 SEE ALSO 🧚

kernel file ./drivers/scsi/scsi.c and friends β€” go read these next, iykyk:


and that's the page, bestie 🫢 it ships from ./drivers/scsi, dated October 2026, still called __starget_for_each_device(9) β€” go forth, hold that host_lock, and stay iconic πŸ’œβœ¨

πŸ“¦ where this page comes from