devm_power_s...by_reference(9)
β¨ devm_power_s...by_reference(9) β¨
okay so this is a page from the Kernel API Manual, and honestly? it's a little baddie of a function π
it's the resource-managed glow-up of power_supply_get_by_reference(), and yes that's the whole personality. it grabs you a power supply reference and then cleans up after itself like a responsible main character. we love to see it π«Ά
πΈ SYNOPSIS πΈ
struct power_supply * devm_power_supply_get_by_reference (struct device
*dev , const char *property );
like literally that's the whole call bestie, go off π₯
π ARGUMENTS π
devβ pointer to the device that's holding the phandle property. it's the device doing the holding, okay? π«Άpropertyβ the name of the property that holds a power supply phandle. so like, the property name string, and inside it lives a phandle pointing at a power supply β¨
π RETURN π
on success you get a reference to a power supply whose name equals the value under property β slay π
otherwise? you get NULL or ERR_PTR. so yeah, check your returns, no cap π (and if it's an ERR_PTR don't go dereferencing it, that's not the vibe, that's undefined behaviour territory fr fr π)
π¦ SEE ALSO π¦
the kernel file lives at ./drivers/power/supply/power_supply_core.c β that's the source of truth, iykyk π
and the whole friend group of related calls, all iconic, all listed here:
power_supply_get_by_name(9)power_supply_get_system_batteries(9)power_supply_put_system_batteries(9)power_supply_put(9)power_supply_get_by_reference(9)power_supply_temp2resist_simple(9)power_supply_vbat2ri(9)power_supply_ocv2cap_simple(9)power_supply_get_property_direct(9)power_supply_set_property_direct(9)power_supply_register(9)devm_power_supply_register(9)power_supply_unregister(9)
ngl,power_supply_put(9)is right there in the list for a reason β a reference you got is a reference you eventually give back. thedevm_prefix just means the cleanup is handled for you when the device goes away π§
and that's the page!! it came from ./drivers/power/supply, dated October 2026, and it's filed under the devm_power_s...by_reference(9) name π mwah, go read power_supply_core.c bestie, it's giving source-of-truth energy πβ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms