From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C71EC07E9B for ; Tue, 20 Jul 2021 22:19:19 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8BB96120A for ; Tue, 20 Jul 2021 22:19:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8BB96120A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1DDF0168F; Wed, 21 Jul 2021 00:18:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1DDF0168F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626819556; bh=BMhZpeETzFRWiIRWlVsRhkwh3lKmGA3IzNTsorOMY7g=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=kIB7naOD6DVgsbB0TTi0QkndbpHuwMWvE//927aeuOIyQJcQoQH0QhbFZtIvqC9PV N2hn6I6KgeWPfwRwTCv8eo1n/ZZhJjXo6h+WNKpt1YHC04rF0kMNqrfPg8pp3Ptsja DUy+FgHN+rTSSQDZQV6tV883IAR56x8EoAADVxK4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A6CF9F80227; Wed, 21 Jul 2021 00:18:25 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C61A8F80256; Wed, 21 Jul 2021 00:18:23 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 2A314F80169 for ; Wed, 21 Jul 2021 00:18:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2A314F80169 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="pRrB/YwC"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="9BroVUBA" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6CAE71FE65; Tue, 20 Jul 2021 22:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626819498; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=buFihF+hISdrP7MN86FA3XGDpK4rCTplRGYeEqV+F74=; b=pRrB/YwCO1S+SIEzns8H4AWtb4nuTncGBX+KNrs0K8nBVktxuHzgSsokphyyffz0FLJ8c7 v4QOGtH1T1kZpjuGdIyXi9xpv2K2lJRatDhR6Yguf+RSg61l/WoGM1ZpKzvPcbYrjt0/8b X9nkSJlKP29wvjQIApkWRmFLWtPruNg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626819498; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=buFihF+hISdrP7MN86FA3XGDpK4rCTplRGYeEqV+F74=; b=9BroVUBAtkJDzrPpYO++pjNd2dpnZUodgHOw7d2SXVYqmAmcmOiSljhOoRCcNo9CD/HtRc 8/WHEk1h3inDa4Cw== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 6731BA3B83; Tue, 20 Jul 2021 22:18:18 +0000 (UTC) Date: Wed, 21 Jul 2021 00:18:18 +0200 Message-ID: From: Takashi Iwai To: Nathan Chancellor Subject: Re: [PATCH v2 09/79] ALSA: als300: Allocate resources with device-managed APIs In-Reply-To: References: <20210715075941.23332-1-tiwai@suse.de> <20210715075941.23332-10-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Tue, 20 Jul 2021 21:45:17 +0200, Nathan Chancellor wrote: > > On Thu, Jul 15, 2021 at 09:58:31AM +0200, Takashi Iwai wrote: > > This patch converts the resource management in PCI als300 driver with > > devres as a clean up. Each manual resource management is converted > > with the corresponding devres helper, and the card object release is > > managed now via card->private_free instead of a lowlevel snd_device. > > > > This should give no user-visible functional changes. > > > > Signed-off-by: Takashi Iwai > > --- > > sound/pci/als300.c | 79 ++++++++++------------------------------------ > > 1 file changed, 17 insertions(+), 62 deletions(-) > > > > diff --git a/sound/pci/als300.c b/sound/pci/als300.c > > index 668008fc21f7..9c94072572a5 100644 > > --- a/sound/pci/als300.c > > +++ b/sound/pci/als300.c > > @@ -163,21 +163,11 @@ static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd) > > snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp); > > } > > > > -static int snd_als300_free(struct snd_als300 *chip) > > +static void snd_als300_free(struct snd_card *card) > > { > > - snd_als300_set_irq_flag(chip, IRQ_DISABLE); > > - if (chip->irq >= 0) > > - free_irq(chip->irq, chip); > > - pci_release_regions(chip->pci); > > - pci_disable_device(chip->pci); > > - kfree(chip); > > - return 0; > > -} > > + struct snd_als300 *chip = card->private_data; > > > > -static int snd_als300_dev_free(struct snd_device *device) > > -{ > > - struct snd_als300 *chip = device->device_data; > > - return snd_als300_free(chip); > > + snd_als300_set_irq_flag(chip, IRQ_DISABLE); > > } > > > > static irqreturn_t snd_als300_interrupt(int irq, void *dev_id) > > @@ -248,11 +238,6 @@ static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id) > > return IRQ_HANDLED; > > } > > > > -static void snd_als300_remove(struct pci_dev *pci) > > -{ > > - snd_card_free(pci_get_drvdata(pci)); > > -} > > - > > static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97, > > unsigned short reg) > > { > > @@ -610,35 +595,22 @@ static void snd_als300_init(struct snd_als300 *chip) > > } > > > > static int snd_als300_create(struct snd_card *card, > > - struct pci_dev *pci, int chip_type, > > - struct snd_als300 **rchip) > > + struct pci_dev *pci, int chip_type) > > { > > - struct snd_als300 *chip; > > + struct snd_als300 *chip = card->private_data; > > void *irq_handler; > > int err; > > > > - static const struct snd_device_ops ops = { > > - .dev_free = snd_als300_dev_free, > > - }; > > - *rchip = NULL; > > - > > - err = pci_enable_device(pci); > > + err = pcim_enable_device(pci); > > if (err < 0) > > return err; > > > > if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) { > > dev_err(card->dev, "error setting 28bit DMA mask\n"); > > - pci_disable_device(pci); > > return -ENXIO; > > } > > pci_set_master(pci); > > > > - chip = kzalloc(sizeof(*chip), GFP_KERNEL); > > - if (chip == NULL) { > > - pci_disable_device(pci); > > - return -ENOMEM; > > - } > > - > > chip->card = card; > > chip->pci = pci; > > chip->irq = -1; > > @@ -646,11 +618,9 @@ static int snd_als300_create(struct snd_card *card, > > spin_lock_init(&chip->reg_lock); > > > > err = pci_request_regions(pci, "ALS300"); > > - if (err < 0) { > > - kfree(chip); > > - pci_disable_device(pci); > > + if (err < 0) > > return err; > > - } > > + > > chip->port = pci_resource_start(pci, 0); > > > > if (chip->chip_type == DEVICE_ALS300_PLUS) > > @@ -658,38 +628,29 @@ static int snd_als300_create(struct snd_card *card, > > else > > irq_handler = snd_als300_interrupt; > > > > - if (request_irq(pci->irq, irq_handler, IRQF_SHARED, > > - KBUILD_MODNAME, chip)) { > > + if (devm_request_irq(&pci->dev, pci->irq, irq_handler, IRQF_SHARED, > > + KBUILD_MODNAME, chip)) { > > dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); > > - snd_als300_free(chip); > > return -EBUSY; > > } > > chip->irq = pci->irq; > > card->sync_irq = chip->irq; > > + card->private_free = snd_als300_free; > > > > snd_als300_init(chip); > > > > err = snd_als300_ac97(chip); > > if (err < 0) { > > dev_err(card->dev, "Could not create ac97\n"); > > - snd_als300_free(chip); > > return err; > > } > > > > err = snd_als300_new_pcm(chip); > > if (err < 0) { > > dev_err(card->dev, "Could not create PCM\n"); > > - snd_als300_free(chip); > > - return err; > > - } > > - > > - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); > > - if (err < 0) { > > - snd_als300_free(chip); > > return err; > > } > > > > - *rchip = chip; > > return 0; > > } > > > > @@ -737,20 +698,16 @@ static int snd_als300_probe(struct pci_dev *pci, > > return -ENOENT; > > } > > > > - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, > > - 0, &card); > > - > > + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, > > + sizeof(*chip), &card); > > if (err < 0) > > return err; > > > > chip_type = pci_id->driver_data; > > > > - err = snd_als300_create(card, pci, chip_type, &chip); > > - if (err < 0) { > > - snd_card_free(card); > > + err = snd_als300_create(card, pci, chip_type); > > + if (err < 0) > > return err; > > - } > > - card->private_data = chip; > > > > strcpy(card->driver, "ALS300"); > > if (chip->chip_type == DEVICE_ALS300_PLUS) > > clang warns: > > sound/pci/als300.c:713:6: error: variable 'chip' is uninitialized when used here [-Werror,-Wuninitialized] > if (chip->chip_type == DEVICE_ALS300_PLUS) > ^~~~ > sound/pci/als300.c:691:25: note: initialize the variable 'chip' to silence this warning > struct snd_als300 *chip; > ^ > = NULL > 1 error generated. Thanks, it was another silly mistake. I'll queue the fix patch below. Takashi -- 8< -- From: Takashi Iwai Subject: [PATCH] ALSA: als300: Fix missing chip initialization The recent code refactoring missed the initialization of the chip variable as its allocation was moved to card->private_data. Let's fix it. Fixes: 21a9314cf93b ("ALSA: als300: Allocate resources with device-managed APIs") Reported-by: Nathan Chancellor Signed-off-by: Takashi Iwai --- sound/pci/als300.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sound/pci/als300.c b/sound/pci/als300.c index 9c94072572a5..b86565dcdbe4 100644 --- a/sound/pci/als300.c +++ b/sound/pci/als300.c @@ -702,6 +702,7 @@ static int snd_als300_probe(struct pci_dev *pci, sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; chip_type = pci_id->driver_data; -- 2.26.2