Message ID | 20180621154356.5438-2-robert.jarzmik@free.fr (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Thu, 21 Jun 2018 17:43:56 +0200, Robert Jarzmik wrote: > > Add a devicetree binding for codecs. This is especially useful if the > AC97 bitclk clock is provided by the codec, as it has to be described in > the devicetree description for the ac97 bus code to aquire it. > > Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> > --- > Special review query: review the "return of_node_get(node)", which > assumes that upon device removal, of_put_node(dev.of_node) will be > called... Is it really done automagically? I couldn't spot it. thanks, Takashi
Takashi Iwai <tiwai@suse.de> writes: >> Special review query: review the "return of_node_get(node)", which >> assumes that upon device removal, of_put_node(dev.of_node) will be >> called... > > Is it really done automagically? I couldn't spot it. Neither could I ... I based this on device_set_of_node_from_dev(), and the it "seemed" logical to me that a device probed from devicetree would take a refcnt on the devicetree node. As the "logical" conflicted with my search for the automagical of_node_get(), I need the special review query. Cheers.
On Fri, 22 Jun 2018 12:41:14 +0200, Robert Jarzmik wrote: > > Takashi Iwai <tiwai@suse.de> writes: > > >> Special review query: review the "return of_node_get(node)", which > >> assumes that upon device removal, of_put_node(dev.of_node) will be > >> called... > > > > Is it really done automagically? I couldn't spot it. > Neither could I ... > > I based this on device_set_of_node_from_dev(), and the it "seemed" logical to me > that a device probed from devicetree would take a refcnt on the devicetree node. > > As the "logical" conflicted with my search for the automagical of_node_get(), I > need the special review query. Hm, some of these users (e.g. drivers/usb/core/*) do call of_node_put() properly at releasing, but some look leaking to me. I don't think we have the common code in the driver core to release dev->of_node, at least. If any, this should be done in ac97_codec_release(), I suppose. Takashi
On Fri, Jun 22, 2018 at 12:49:49PM +0200, Takashi Iwai wrote: > Hm, some of these users (e.g. drivers/usb/core/*) do call > of_node_put() properly at releasing, but some look leaking to me. > I don't think we have the common code in the driver core to release > dev->of_node, at least. > If any, this should be done in ac97_codec_release(), I suppose. Yeah, I'd expect this to be handled in each bus.
diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c index 31f858eceffc..c8e20dd8786f 100644 --- a/sound/ac97/bus.c +++ b/sound/ac97/bus.c @@ -13,6 +13,7 @@ #include <linux/idr.h> #include <linux/list.h> #include <linux/mutex.h> +#include <linux/of.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/slab.h> @@ -68,6 +69,27 @@ ac97_codec_find(struct ac97_controller *ac97_ctrl, unsigned int codec_num) return ac97_ctrl->codecs[codec_num]; } +static struct device_node * +ac97_of_get_child_device(struct ac97_controller *ac97_ctrl, int idx, + unsigned int vendor_id) +{ + struct device_node *node; + u32 reg; + char compat[] = "ac97,0000,0000"; + + snprintf(compat, sizeof(compat), "ac97,%04x,%04x", + vendor_id >> 16, vendor_id & 0xffff); + + for_each_child_of_node(ac97_ctrl->parent->of_node, node) { + if ((idx != of_property_read_u32(node, "reg", ®)) || + !of_device_is_compatible(node, compat)) + continue; + return of_node_get(node); + } + + return NULL; +} + static void ac97_codec_release(struct device *dev) { struct ac97_codec_device *adev; @@ -98,6 +120,8 @@ static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx, device_initialize(&codec->dev); dev_set_name(&codec->dev, "%s:%u", dev_name(ac97_ctrl->parent), idx); + codec->dev.of_node = ac97_of_get_child_device(ac97_ctrl, idx, + vendor_id); ret = device_add(&codec->dev); if (ret)
Add a devicetree binding for codecs. This is especially useful if the AC97 bitclk clock is provided by the codec, as it has to be described in the devicetree description for the ac97 bus code to aquire it. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> --- Special review query: review the "return of_node_get(node)", which assumes that upon device removal, of_put_node(dev.of_node) will be called... --- sound/ac97/bus.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)