From patchwork Mon Jul 16 13:48:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 10526833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55FBD600D0 for ; Mon, 16 Jul 2018 13:48:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 484E928ACE for ; Mon, 16 Jul 2018 13:48:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C6A928AED; Mon, 16 Jul 2018 13:48:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B9CF628B1E for ; Mon, 16 Jul 2018 13:48:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0B7B06E4AA; Mon, 16 Jul 2018 13:48:22 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 79A3A6E4AB; Mon, 16 Jul 2018 13:48:20 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 12736AD90; Mon, 16 Jul 2018 13:48:19 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Date: Mon, 16 Jul 2018 15:48:14 +0200 Message-Id: <20180716134815.21365-3-tiwai@suse.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716134815.21365-1-tiwai@suse.de> References: <20180716134815.21365-1-tiwai@suse.de> Subject: [Intel-gfx] [PATCH 2/3] ALSA: hda/i915: Associate audio component with devres X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jim Qu , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP The HD-audio i915 binding code contains a single pointer, hdac_acomp, for allowing the access to audio component from the master bind/unbind callbacks. This was needed because the callbacks pass only the device pointer and we can't guarantee the object type assigned to the drvdata (which is free for each controller driver implementation). And this implementation will be a problem if we support multiple components for different DRM drivers, not only i915. As a solution, allocate the audio component object via devres and associate it with the given device, so that the component callbacks can refer to it via devres_find(). The removal of the object is still done half-manually via devres_destroy() to make the code consistent (although it may work without the explicit call). Also, the snd_hda_i915_register_notifier() had the reference to hdac_acomp as well. In this patch, the corresponding code is removed by passing hdac_bus object to the function, too. Signed-off-by: Takashi Iwai --- include/sound/hda_i915.h | 6 ++++-- sound/hda/hdac_i915.c | 34 +++++++++++++++++++++------------- sound/pci/hda/patch_hdmi.c | 5 +++-- sound/soc/codecs/hdac_hdmi.c | 2 +- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/include/sound/hda_i915.h b/include/sound/hda_i915.h index f69ea84e7b65..648263791559 100644 --- a/include/sound/hda_i915.h +++ b/include/sound/hda_i915.h @@ -17,7 +17,8 @@ int snd_hdac_acomp_get_eld(struct hdac_device *codec, hda_nid_t nid, int dev_id, bool *audio_enabled, char *buffer, int max_bytes); int snd_hdac_i915_init(struct hdac_bus *bus); int snd_hdac_i915_exit(struct hdac_bus *bus); -int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *); +int snd_hdac_i915_register_notifier(struct hdac_bus *bus, + const struct drm_audio_component_audio_ops *ops); #else static inline int snd_hdac_set_codec_wakeup(struct hdac_bus *bus, bool enable) { @@ -49,7 +50,8 @@ static inline int snd_hdac_i915_exit(struct hdac_bus *bus) { return 0; } -static inline int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *ops) +static inline int snd_hdac_i915_register_notifier(struct hdac_bus *bus, + const struct drm_audio_component_audio_ops *ops) { return -ENODEV; } diff --git a/sound/hda/hdac_i915.c b/sound/hda/hdac_i915.c index 1a88c1aaf9bb..861b77bbc7df 100644 --- a/sound/hda/hdac_i915.c +++ b/sound/hda/hdac_i915.c @@ -22,7 +22,14 @@ #include #include -static struct drm_audio_component *hdac_acomp; +static void hdac_acomp_release(struct device *dev, void *res) +{ +} + +static struct drm_audio_component *hdac_get_acomp(struct device *dev) +{ + return devres_find(dev, hdac_acomp_release, NULL, NULL); +} /** * snd_hdac_set_codec_wakeup - Enable / disable HDMI/DP codec wakeup @@ -262,7 +269,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_acomp_get_eld); static int hdac_component_master_bind(struct device *dev) { - struct drm_audio_component *acomp = hdac_acomp; + struct drm_audio_component *acomp = hdac_get_acomp(dev); int ret; ret = component_bind_all(dev, acomp); @@ -294,7 +301,7 @@ static int hdac_component_master_bind(struct device *dev) static void hdac_component_master_unbind(struct device *dev) { - struct drm_audio_component *acomp = hdac_acomp; + struct drm_audio_component *acomp = hdac_get_acomp(dev); module_put(acomp->ops->owner); component_unbind_all(dev, acomp); @@ -314,6 +321,7 @@ static int hdac_component_master_match(struct device *dev, void *data) /** * snd_hdac_i915_register_notifier - Register i915 audio component ops + * @bus: HDA core bus * @aops: i915 audio component ops * * This function is supposed to be used only by a HD-audio controller @@ -323,12 +331,13 @@ static int hdac_component_master_match(struct device *dev, void *data) * * Returns zero for success or a negative error code. */ -int snd_hdac_i915_register_notifier(const struct drm_audio_component_audio_ops *aops) +int snd_hdac_i915_register_notifier(struct hdac_bus *bus, + const struct drm_audio_component_audio_ops *aops) { - if (!hdac_acomp) + if (!bus->audio_component) return -ENODEV; - hdac_acomp->audio_ops = aops; + bus->audio_component->audio_ops = aops; return 0; } EXPORT_SYMBOL_GPL(snd_hdac_i915_register_notifier); @@ -365,18 +374,19 @@ int snd_hdac_i915_init(struct hdac_bus *bus) struct drm_audio_component *acomp; int ret; - if (WARN_ON(hdac_acomp)) + if (WARN_ON(hdac_get_acomp(dev))) return -EBUSY; if (!i915_gfx_present()) return -ENODEV; - i915_acomp = kzalloc(sizeof(*i915_acomp), GFP_KERNEL); + i915_acomp = devres_alloc(hdac_acomp_release, sizeof(*i915_acomp), + GFP_KERNEL); if (!i915_acomp) return -ENOMEM; acomp = &i915_acomp->base; bus->audio_component = acomp; - hdac_acomp = acomp; + devres_add(dev, acomp); component_match_add(dev, &match, hdac_component_master_match, bus); ret = component_master_add_with_match(dev, &hdac_component_master_ops, @@ -400,9 +410,8 @@ int snd_hdac_i915_init(struct hdac_bus *bus) out_master_del: component_master_del(dev, &hdac_component_master_ops); out_err: - kfree(acomp); bus->audio_component = NULL; - hdac_acomp = NULL; + devres_destroy(dev, hdac_acomp_release, NULL, NULL); dev_info(dev, "failed to add i915 component master (%d)\n", ret); return ret; @@ -434,9 +443,8 @@ int snd_hdac_i915_exit(struct hdac_bus *bus) component_master_del(dev, &hdac_component_master_ops); - kfree(acomp); bus->audio_component = NULL; - hdac_acomp = NULL; + devres_destroy(dev, hdac_acomp_release, NULL, NULL); return 0; } diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index c0847017114c..bf174a013f2d 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -2288,7 +2288,7 @@ static void generic_hdmi_free(struct hda_codec *codec) int pin_idx, pcm_idx; if (codec_has_acomp(codec)) - snd_hdac_i915_register_notifier(NULL); + snd_hdac_i915_register_notifier(&codec->bus->core, NULL); for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); @@ -2518,7 +2518,8 @@ static void register_i915_notifier(struct hda_codec *codec) */ wmb(); spec->drm_audio_ops.pin_eld_notify = intel_pin_eld_notify; - snd_hdac_i915_register_notifier(&spec->drm_audio_ops); + snd_hdac_i915_register_notifier(&codec->bus->core, + &spec->drm_audio_ops); } /* setup_stream ops override for HSW+ */ diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c index 460075475f20..2b7c33db4ded 100644 --- a/sound/soc/codecs/hdac_hdmi.c +++ b/sound/soc/codecs/hdac_hdmi.c @@ -1812,7 +1812,7 @@ static int hdmi_codec_probe(struct snd_soc_component *component) return ret; aops.audio_ptr = hdev; - ret = snd_hdac_i915_register_notifier(&aops); + ret = snd_hdac_i915_register_notifier(hdev->bus, &aops); if (ret < 0) { dev_err(&hdev->dev, "notifier register failed: err: %d\n", ret); return ret;