From patchwork Tue Jul 13 14:28:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474737 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=-18.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, USER_AGENT_GIT 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 29AADC07E95 for ; Tue, 13 Jul 2021 14:31:05 +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 A2C66610CB for ; Tue, 13 Jul 2021 14:31:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2C66610CB 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 485EA16B1; Tue, 13 Jul 2021 16:30:13 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 485EA16B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186663; bh=2BGYWrXBGZJ2umOkUHgE/h0NhuwHvsi2h/cJRb6EGOY=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Vi+5GzDlfU06RPCialtAfgwDUTFtQJVYvJI960snpwfJw3OdGZhf99CGu9HGcCKKA 5BJ0eqiCzXWF2g53sp1xBPfMktjMqdDdfIkFUQL6NcKCTnMnAF6aJFEgDbnfw4DiIx 13UtENaDmUhtCiilDcWdKlB26YgZ7Rw0e+wyRmtY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3D92CF804F2; Tue, 13 Jul 2021 16:29:17 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id BEBFAF804F2; Tue, 13 Jul 2021 16:29:15 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 2E11AF8020C for ; Tue, 13 Jul 2021 16:29:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2E11AF8020C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="kR0zrkhv"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Oj4u7Svh" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id F3A8C22837 for ; Tue, 13 Jul 2021 14:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186549; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5joqZEry4ixJz2fagLW3ZFdGm3Atk1p7KkBSww/qRU4=; b=kR0zrkhvpUeaHU5T9chwBcG2gNFxyUAbvXY9fd3PNo49TKvMnyDocnxjsm/7Txw1cPCGrE BJ1mbSGPV2RFvF7NaLG/Rek17Bam4xvpI4B87Tv5NnnyIwWzmgn3Sp+4pIY/tSvUKifLBC cuCSbvasKPxvRnsuYPcGOX26A13+iyM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186549; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5joqZEry4ixJz2fagLW3ZFdGm3Atk1p7KkBSww/qRU4=; b=Oj4u7SvhrvYo6jNZF+VDw8yOmb9zwnFwGo2m7vBS4NFWaCw/++ZWZL+A6mCdU5MKbdHpBe vGOo5B3trGS876Bw== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id E44CBA3B83; Tue, 13 Jul 2021 14:29:08 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 01/51] ALSA: core: Add device-managed page allocator helper Date: Tue, 13 Jul 2021 16:28:07 +0200 Message-Id: <20210713142857.19654-2-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This is a preparation for allowing devres usages more widely in various sound drivers. As a first step, this patch adds a new allocator function, snd_devm_alloc_pages(), to manage the allocated pages via devres, so that the pages will be automagically released as device unbinding. Unlike the old snd_dma_alloc_pages(), the new function returns directly the snd_dma_buffer pointer. The caller needs NULL-check for the allocation error appropriately. Also, since a real device pointer is mandatory for devres, SNDRV_DMA_TYPE_CONTINUOUS or SNDRV_DMA_TYPE_VMALLOC type can't be used for this function. Signed-off-by: Takashi Iwai --- include/sound/memalloc.h | 4 ++++ sound/core/memalloc.c | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h index 44d87775b352..d22c9387b2ba 100644 --- a/include/sound/memalloc.h +++ b/include/sound/memalloc.h @@ -79,5 +79,9 @@ struct page *snd_sgbuf_get_page(struct snd_dma_buffer *dmab, size_t offset); unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab, unsigned int ofs, unsigned int size); +/* device-managed memory allocator */ +struct snd_dma_buffer *snd_devm_alloc_pages(struct device *dev, int type, + size_t size); + #endif /* __SOUND_MEMALLOC_H */ diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c index 83b79edfa52d..3a78fdad1ab4 100644 --- a/sound/core/memalloc.c +++ b/sound/core/memalloc.c @@ -127,6 +127,52 @@ void snd_dma_free_pages(struct snd_dma_buffer *dmab) } EXPORT_SYMBOL(snd_dma_free_pages); +/* called by devres */ +static void __snd_release_pages(struct device *dev, void *res) +{ + snd_dma_free_pages(res); +} + +/** + * snd_devm_alloc_pages - allocate the buffer and manage with devres + * @dev: the device pointer + * @type: the DMA buffer type + * @size: the buffer size to allocate + * + * Allocate buffer pages depending on the given type and manage using devres. + * The pages will be released automatically at the device removal. + * + * Unlike snd_dma_alloc_pages(), this function requires the real device pointer, + * hence it can't work with SNDRV_DMA_TYPE_CONTINUOUS or + * SNDRV_DMA_TYPE_VMALLOC type. + * + * The function returns the snd_dma_buffer object at success, or NULL if failed. + */ +struct snd_dma_buffer * +snd_devm_alloc_pages(struct device *dev, int type, size_t size) +{ + struct snd_dma_buffer *dmab; + int err; + + if (WARN_ON(type == SNDRV_DMA_TYPE_CONTINUOUS || + type == SNDRV_DMA_TYPE_VMALLOC)) + return NULL; + + dmab = devres_alloc(__snd_release_pages, sizeof(*dmab), GFP_KERNEL); + if (!dmab) + return NULL; + + err = snd_dma_alloc_pages(type, dev, size, dmab); + if (err < 0) { + devres_free(dmab); + return NULL; + } + + devres_add(dev, dmab); + return dmab; +} +EXPORT_SYMBOL_GPL(snd_devm_alloc_pages); + /** * snd_dma_buffer_mmap - perform mmap of the given DMA buffer * @dmab: buffer allocation information From patchwork Tue Jul 13 14:28:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474736 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=-18.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, USER_AGENT_GIT 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 03032C07E95 for ; Tue, 13 Jul 2021 14:31:54 +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 8040A610CB for ; Tue, 13 Jul 2021 14:31:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8040A610CB 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 136EB16FF; Tue, 13 Jul 2021 16:31:02 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 136EB16FF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186712; bh=EmXsO8A6hKMGipEIU2L5NclT23mD126IniGJcoPq4wg=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Sh1eEGai5NBMmI9LXyFXGx5AMQe5k2jtp6c52SZa+v6FEDweUf43AXK4g9y6e2Kbp HAKJG/gjd9pCOEtKULxseiCWIZV8kpHY14yhhmqNqcChpcx7ysn6OzanFc+DKJ9+VX AzYe+roXxmq07OaOHIErNrxutzRG3dgEowY76UZo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id D649CF80517; Tue, 13 Jul 2021 16:29:24 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1F891F80430; Tue, 13 Jul 2021 16:29:20 +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 423F5F80430 for ; Tue, 13 Jul 2021 16:29:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 423F5F80430 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ChJPP+/2"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="V50k/E+z" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id EF8D3201DA for ; Tue, 13 Jul 2021 14:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186550; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IYGwEgxSe3lfwTayzEuKCrhyKkUnngXAooaOVfsxXoc=; b=ChJPP+/2w8O+L6egzS1FUytvvhHIPBkJCX6+o591rsM8rYjvOJR7qA9A3QYDFNzvht5dzb x85ZGVPv5Jl184GuhytO5Uw4BM8Tt4u0DGCG1lEvSe5yT62UlmOEbEWi6dqxlLx/bI1sKo 0RnxgfmQGYxyz8He6lXvHL0CgiatCrw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186550; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IYGwEgxSe3lfwTayzEuKCrhyKkUnngXAooaOVfsxXoc=; b=V50k/E+zbKJYlWQMzPiJMsfFod9+0MbLMTfTB6Ivys8wR12vWX+JmJMHMcb69uTVkztTf1 tWfvxuwJnmAWIEBA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id DC806A3B88; Tue, 13 Jul 2021 14:29:10 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 03/51] ALSA: intel8x0: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:09 +0200 Message-Id: <20210713142857.19654-4-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch refactors the intel8x0 and intel8x0m driver codes using devres and gets rid of the driver remove callback. The conversion is fairly straightforward: each API call is replaced with the device-managed API function, e.g. pci_enable_device() -> pcim_enable_device(), and so on. The buffer descriptor list is allocated with a new API, snd_devm_alloc_pages(). A slight code structure change is that the intel8x0 object is allocated as a card's private_data instead of the own lowlevel snd_device object. This simplifies the resource management. And, the take-down procedure is triggered via card->private_free, and it's registered at the end of the whole initialization, i.e. after the all resources get properly managed. The only not-devres-managed resource is the irq handler. Since we need to release at suspend and re-acquire at resume (otherwise something weird happens on some machines), this is still managed manually. But the rest are all freed automatically. The end result is a good amount of code reduction. Signed-off-by: Takashi Iwai --- sound/pci/intel8x0.c | 140 +++++++++++++----------------------------- sound/pci/intel8x0m.c | 139 ++++++++++++----------------------------- 2 files changed, 81 insertions(+), 198 deletions(-) diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c index 6a436a2ce26a..67cb65a53edd 100644 --- a/sound/pci/intel8x0.c +++ b/sound/pci/intel8x0.c @@ -378,7 +378,7 @@ struct intel8x0 { spinlock_t reg_lock; u32 bdbars_count; - struct snd_dma_buffer bdbars; + struct snd_dma_buffer *bdbars; u32 int_sta_reg; /* interrupt status register */ u32 int_sta_mask; /* interrupt status mask */ }; @@ -2528,8 +2528,9 @@ static int snd_intel8x0_chip_init(struct intel8x0 *chip, int probing) return 0; } -static int snd_intel8x0_free(struct intel8x0 *chip) +static void snd_intel8x0_free(struct snd_card *card) { + struct intel8x0 *chip = card->private_data; unsigned int i; if (chip->irq < 0) @@ -2552,16 +2553,6 @@ static int snd_intel8x0_free(struct intel8x0 *chip) __hw_end: if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->bdbars.area) - snd_dma_free_pages(&chip->bdbars); - if (chip->addr) - pci_iounmap(chip->pci, chip->addr); - if (chip->bmaddr) - pci_iounmap(chip->pci, chip->bmaddr); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; } #ifdef CONFIG_PM_SLEEP @@ -2831,12 +2822,6 @@ static void snd_intel8x0_proc_init(struct intel8x0 *chip) snd_intel8x0_proc_read); } -static int snd_intel8x0_dev_free(struct snd_device *device) -{ - struct intel8x0 *chip = device->device_data; - return snd_intel8x0_free(chip); -} - struct ich_reg_info { unsigned int int_sta_mask; unsigned int offset; @@ -2880,19 +2865,15 @@ static int snd_intel8x0_inside_vm(struct pci_dev *pci) return result; } -static int snd_intel8x0_create(struct snd_card *card, - struct pci_dev *pci, - unsigned long device_type, - struct intel8x0 **r_intel8x0) +static int snd_intel8x0_init(struct snd_card *card, + struct pci_dev *pci, + unsigned long device_type) { - struct intel8x0 *chip; + struct intel8x0 *chip = card->private_data; int err; unsigned int i; unsigned int int_sta_masks; struct ichdev *ichdev; - static const struct snd_device_ops ops = { - .dev_free = snd_intel8x0_dev_free, - }; static const unsigned int bdbars[] = { 3, /* DEVICE_INTEL */ @@ -2925,17 +2906,10 @@ static int snd_intel8x0_create(struct snd_card *card, }; const struct ich_reg_info *tbl; - *r_intel8x0 = NULL; - - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } spin_lock_init(&chip->reg_lock); chip->device_type = device_type; chip->card = card; @@ -2961,38 +2935,23 @@ static int snd_intel8x0_create(struct snd_card *card, chip->fix_nocache = 1; /* enable workaround */ err = pci_request_regions(pci, card->shortname); - if (err < 0) { - kfree(chip); - pci_disable_device(pci); + if (err < 0) return err; - } if (device_type == DEVICE_ALI) { /* ALI5455 has no ac97 region */ - chip->bmaddr = pci_iomap(pci, 0, 0); - goto port_inited; - } - - if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */ - chip->addr = pci_iomap(pci, 2, 0); - else - chip->addr = pci_iomap(pci, 0, 0); - if (!chip->addr) { - dev_err(card->dev, "AC'97 space ioremap problem\n"); - snd_intel8x0_free(chip); - return -EIO; + chip->bmaddr = pcim_iomap(pci, 0, 0); + } else { + if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */ + chip->addr = pcim_iomap(pci, 2, 0); + else + chip->addr = pcim_iomap(pci, 0, 0); + if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */ + chip->bmaddr = pcim_iomap(pci, 3, 0); + else + chip->bmaddr = pcim_iomap(pci, 1, 0); } - if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */ - chip->bmaddr = pci_iomap(pci, 3, 0); - else - chip->bmaddr = pci_iomap(pci, 1, 0); - port_inited: - if (!chip->bmaddr) { - dev_err(card->dev, "Controller space ioremap problem\n"); - snd_intel8x0_free(chip); - return -EIO; - } chip->bdbars_count = bdbars[device_type]; /* initialize offsets */ @@ -3028,21 +2987,20 @@ static int snd_intel8x0_create(struct snd_card *card, /* allocate buffer descriptor lists */ /* the start of each lists must be aligned to 8 bytes */ - if (snd_dma_alloc_pages(intel8x0_dma_type(chip), &pci->dev, - chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2, - &chip->bdbars) < 0) { - snd_intel8x0_free(chip); - dev_err(card->dev, "cannot allocate buffer descriptors\n"); + chip->bdbars = snd_devm_alloc_pages(&pci->dev, intel8x0_dma_type(chip), + chip->bdbars_count * sizeof(u32) * + ICH_MAX_FRAGS * 2); + if (!chip->bdbars) return -ENOMEM; - } + /* tables must be aligned to 8 bytes here, but the kernel pages are much bigger, so we don't care (on i386) */ int_sta_masks = 0; for (i = 0; i < chip->bdbars_count; i++) { ichdev = &chip->ichd[i]; - ichdev->bdbar = ((__le32 *)chip->bdbars.area) + + ichdev->bdbar = ((__le32 *)chip->bdbars->area) + (i * ICH_MAX_FRAGS * 2); - ichdev->bdbar_addr = chip->bdbars.addr + + ichdev->bdbar_addr = chip->bdbars->addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2); int_sta_masks |= ichdev->int_sta_mask; } @@ -3076,28 +3034,24 @@ static int snd_intel8x0_create(struct snd_card *card, chip->codec_isr_bits |= chip->codec_bit[i]; err = snd_intel8x0_chip_init(chip, 1); - if (err < 0) { - snd_intel8x0_free(chip); + if (err < 0) return err; - } /* request irq after initializaing int_sta_mask, etc */ + /* NOTE: we don't use devm version here since it's released / + * re-acquired in PM callbacks. + * It's released explicitly in snd_intel8x0_free(), too. + */ if (request_irq(pci->irq, snd_intel8x0_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_intel8x0_free(chip); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_intel8x0_free(chip); - return err; - } + card->private_free = snd_intel8x0_free; - *r_intel8x0 = chip; return 0; } @@ -3163,9 +3117,11 @@ static int snd_intel8x0_probe(struct pci_dev *pci, int err; struct shortname_table *name; - err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; if (spdif_aclink < 0) spdif_aclink = check_default_spdif_aclink(pci); @@ -3199,23 +3155,16 @@ static int snd_intel8x0_probe(struct pci_dev *pci, buggy_irq = 0; } - err = snd_intel8x0_create(card, pci, pci_id->driver_data, &chip); - if (err < 0) { - snd_card_free(card); + err = snd_intel8x0_init(card, pci, pci_id->driver_data); + if (err < 0) return err; - } - card->private_data = chip; err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_intel8x0_pcm(chip); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } snd_intel8x0_proc_init(chip); @@ -3233,24 +3182,17 @@ static int snd_intel8x0_probe(struct pci_dev *pci, } err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } + pci_set_drvdata(pci, card); return 0; } -static void snd_intel8x0_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver intel8x0_driver = { .name = KBUILD_MODNAME, .id_table = snd_intel8x0_ids, .probe = snd_intel8x0_probe, - .remove = snd_intel8x0_remove, .driver = { .pm = INTEL8X0_PM_OPS, }, diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c index b96fce6cbd83..7de3cb2f17b5 100644 --- a/sound/pci/intel8x0m.c +++ b/sound/pci/intel8x0m.c @@ -182,7 +182,7 @@ struct intel8x0m { spinlock_t reg_lock; - struct snd_dma_buffer bdbars; + struct snd_dma_buffer *bdbars; u32 bdbars_count; u32 int_sta_reg; /* interrupt status register */ u32 int_sta_mask; /* interrupt status mask */ @@ -947,8 +947,9 @@ static int snd_intel8x0m_chip_init(struct intel8x0m *chip, int probing) return 0; } -static int snd_intel8x0m_free(struct intel8x0m *chip) +static void snd_intel8x0m_free(struct snd_card *card) { + struct intel8x0m *chip = card->private_data; unsigned int i; if (chip->irq < 0) @@ -962,16 +963,6 @@ static int snd_intel8x0m_free(struct intel8x0m *chip) __hw_end: if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->bdbars.area) - snd_dma_free_pages(&chip->bdbars); - if (chip->addr) - pci_iounmap(chip->pci, chip->addr); - if (chip->bmaddr) - pci_iounmap(chip->pci, chip->bmaddr); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; } #ifdef CONFIG_PM_SLEEP @@ -1047,47 +1038,30 @@ static void snd_intel8x0m_proc_init(struct intel8x0m *chip) snd_intel8x0m_proc_read); } -static int snd_intel8x0m_dev_free(struct snd_device *device) -{ - struct intel8x0m *chip = device->device_data; - return snd_intel8x0m_free(chip); -} - struct ich_reg_info { unsigned int int_sta_mask; unsigned int offset; }; -static int snd_intel8x0m_create(struct snd_card *card, - struct pci_dev *pci, - unsigned long device_type, - struct intel8x0m **r_intel8x0m) +static int snd_intel8x0m_init(struct snd_card *card, + struct pci_dev *pci, + unsigned long device_type) { - struct intel8x0m *chip; + struct intel8x0m *chip = card->private_data; int err; unsigned int i; unsigned int int_sta_masks; struct ichdev *ichdev; - static const struct snd_device_ops ops = { - .dev_free = snd_intel8x0m_dev_free, - }; static const struct ich_reg_info intel_regs[2] = { { ICH_MIINT, 0 }, { ICH_MOINT, 0x10 }, }; const struct ich_reg_info *tbl; - *r_intel8x0m = NULL; - - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } spin_lock_init(&chip->reg_lock); chip->device_type = device_type; chip->card = card; @@ -1095,37 +1069,21 @@ static int snd_intel8x0m_create(struct snd_card *card, chip->irq = -1; err = pci_request_regions(pci, card->shortname); - if (err < 0) { - kfree(chip); - pci_disable_device(pci); + if (err < 0) return err; - } if (device_type == DEVICE_ALI) { /* ALI5455 has no ac97 region */ - chip->bmaddr = pci_iomap(pci, 0, 0); - goto port_inited; - } - - if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */ - chip->addr = pci_iomap(pci, 2, 0); - else - chip->addr = pci_iomap(pci, 0, 0); - if (!chip->addr) { - dev_err(card->dev, "AC'97 space ioremap problem\n"); - snd_intel8x0m_free(chip); - return -EIO; - } - if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */ - chip->bmaddr = pci_iomap(pci, 3, 0); - else - chip->bmaddr = pci_iomap(pci, 1, 0); - -port_inited: - if (!chip->bmaddr) { - dev_err(card->dev, "Controller space ioremap problem\n"); - snd_intel8x0m_free(chip); - return -EIO; + chip->bmaddr = pcim_iomap(pci, 0, 0); + } else { + if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */ + chip->addr = pcim_iomap(pci, 2, 0); + else + chip->addr = pcim_iomap(pci, 0, 0); + if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */ + chip->bmaddr = pcim_iomap(pci, 3, 0); + else + chip->bmaddr = pcim_iomap(pci, 1, 0); } /* initialize offsets */ @@ -1153,19 +1111,19 @@ static int snd_intel8x0m_create(struct snd_card *card, /* allocate buffer descriptor lists */ /* the start of each lists must be aligned to 8 bytes */ - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, - chip->bdbars_count * sizeof(u32) * ICH_MAX_FRAGS * 2, - &chip->bdbars) < 0) { - snd_intel8x0m_free(chip); + chip->bdbars = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, + chip->bdbars_count * sizeof(u32) * + ICH_MAX_FRAGS * 2); + if (!chip->bdbars) return -ENOMEM; - } + /* tables must be aligned to 8 bytes here, but the kernel pages are much bigger, so we don't care (on i386) */ int_sta_masks = 0; for (i = 0; i < chip->bdbars_count; i++) { ichdev = &chip->ichd[i]; - ichdev->bdbar = ((__le32 *)chip->bdbars.area) + (i * ICH_MAX_FRAGS * 2); - ichdev->bdbar_addr = chip->bdbars.addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2); + ichdev->bdbar = ((__le32 *)chip->bdbars->area) + (i * ICH_MAX_FRAGS * 2); + ichdev->bdbar_addr = chip->bdbars->addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2); int_sta_masks |= ichdev->int_sta_mask; } chip->int_sta_reg = ICH_REG_GLOB_STA; @@ -1174,27 +1132,23 @@ static int snd_intel8x0m_create(struct snd_card *card, pci_set_master(pci); err = snd_intel8x0m_chip_init(chip, 1); - if (err < 0) { - snd_intel8x0m_free(chip); + if (err < 0) return err; - } + /* NOTE: we don't use devm version here since it's released / + * re-acquired in PM callbacks. + * It's released explicitly in snd_intel8x0m_free(), too. + */ if (request_irq(pci->irq, snd_intel8x0m_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_intel8x0m_free(chip); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_intel8x0m_free(chip); - return err; - } + card->private_free = snd_intel8x0m_free; - *r_intel8x0m = chip; return 0; } @@ -1232,9 +1186,11 @@ static int snd_intel8x0m_probe(struct pci_dev *pci, int err; struct shortname_table *name; - err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; strcpy(card->driver, "ICH-MODEM"); strcpy(card->shortname, "Intel ICH"); @@ -1246,23 +1202,16 @@ static int snd_intel8x0m_probe(struct pci_dev *pci, } strcat(card->shortname," Modem"); - err = snd_intel8x0m_create(card, pci, pci_id->driver_data, &chip); - if (err < 0) { - snd_card_free(card); + err = snd_intel8x0m_init(card, pci, pci_id->driver_data); + if (err < 0) return err; - } - card->private_data = chip; err = snd_intel8x0m_mixer(chip, ac97_clock); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_intel8x0m_pcm(chip); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } snd_intel8x0m_proc_init(chip); @@ -1270,24 +1219,16 @@ static int snd_intel8x0m_probe(struct pci_dev *pci, card->shortname, chip->irq); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); return 0; } -static void snd_intel8x0m_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver intel8x0m_driver = { .name = KBUILD_MODNAME, .id_table = snd_intel8x0m_ids, .probe = snd_intel8x0m_probe, - .remove = snd_intel8x0m_remove, .driver = { .pm = INTEL8X0M_PM_OPS, }, From patchwork Tue Jul 13 14:28:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474734 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=-18.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, USER_AGENT_GIT 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 3A969C07E95 for ; Tue, 13 Jul 2021 14:33:16 +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 BB0AF610C7 for ; Tue, 13 Jul 2021 14:33:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB0AF610C7 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 530B31701; Tue, 13 Jul 2021 16:32:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 530B31701 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186794; bh=CEUUEMRpKh2q+wEKO3UkqbaUVHguEKirBq7NjDfVM0E=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LR7DkuWsWtcFNObsWJdrb+o4cH82HN4tOI5eruRFF1Rq0iUyzRuT7lsYtkORuMduj GTtzmgnAhkl2A6RMWh9fnQd7q8PKraCXRC5wzKkzlMFl0h73A1LJvHsaeMFvt1iqb0 J1wMVQjOoxTNyTFJWA+87ch3n8bNgkwDq115sBew= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 881DCF8054A; Tue, 13 Jul 2021 16:29:43 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 97758F804FB; Tue, 13 Jul 2021 16:29:27 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 DD404F804E1 for ; Tue, 13 Jul 2021 16:29:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DD404F804E1 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="I5IphAE7"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="7nKPDUpg" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id ACC0D22837 for ; Tue, 13 Jul 2021 14:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186551; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJDCaxedyEx7rQY8uxQVc9bkBE7FagFDqODBfkzm5cU=; b=I5IphAE77fxUqBXbZxhua0lKknq/Xi4vLW7CC5C+87SFOz3+49XgZGMck7N5fmu5nIQzqt yqi1o4rFwaK3hXXZBoT80jNznE8sR6W/s9anapXQNbIi854Cm3W+aJ//DCcbPQBCQRLKyR +CSM1ND0jcCqKbhmfWWMmh/hrLFevYA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186551; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EJDCaxedyEx7rQY8uxQVc9bkBE7FagFDqODBfkzm5cU=; b=7nKPDUpgx6n22H8M7dYCV6RivIlsdap+2+Y57c7Xq9BMwva6/LvXpEaC2G1EXjYYyyA0yL Afk8Nhu+ScDecMBA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id A5B0FA3B88; Tue, 13 Jul 2021 14:29:11 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 04/51] ALSA: atiixp: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:10 +0200 Message-Id: <20210713142857.19654-5-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" Like the previous patch, this patch converts the resource allocations with device-managed API calls, so that we can reduce resource-free calls. The atiixp drivers are simpler than intel8x0, and even the irq can be allocated with devres. The end result is a good amount of code reduction. Signed-off-by: Takashi Iwai --- sound/pci/atiixp.c | 92 +++++++++------------------------------- sound/pci/atiixp_modem.c | 92 +++++++++------------------------------- 2 files changed, 40 insertions(+), 144 deletions(-) diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c index 5f8aa35c4bea..b8e035d5930d 100644 --- a/sound/pci/atiixp.c +++ b/sound/pci/atiixp.c @@ -1530,87 +1530,44 @@ static void snd_atiixp_proc_init(struct atiixp *chip) * destructor */ -static int snd_atiixp_free(struct atiixp *chip) +static void snd_atiixp_free(struct snd_card *card) { - if (chip->irq < 0) - goto __hw_end; - snd_atiixp_chip_stop(chip); - - __hw_end: - if (chip->irq >= 0) - free_irq(chip->irq, chip); - iounmap(chip->remap_addr); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; -} - -static int snd_atiixp_dev_free(struct snd_device *device) -{ - struct atiixp *chip = device->device_data; - return snd_atiixp_free(chip); + snd_atiixp_chip_stop(card->private_data); } /* * constructor for chip instance */ -static int snd_atiixp_create(struct snd_card *card, - struct pci_dev *pci, - struct atiixp **r_chip) +static int snd_atiixp_init(struct snd_card *card, struct pci_dev *pci) { - static const struct snd_device_ops ops = { - .dev_free = snd_atiixp_dev_free, - }; - struct atiixp *chip; + struct atiixp *chip = card->private_data; int err; - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } - spin_lock_init(&chip->reg_lock); mutex_init(&chip->open_mutex); chip->card = card; chip->pci = pci; chip->irq = -1; - err = pci_request_regions(pci, "ATI IXP AC97"); - if (err < 0) { - pci_disable_device(pci); - kfree(chip); + err = pcim_iomap_regions(pci, 1 << 0, "ATI IXP AC97"); + if (err < 0) return err; - } chip->addr = pci_resource_start(pci, 0); - chip->remap_addr = pci_ioremap_bar(pci, 0); - if (chip->remap_addr == NULL) { - dev_err(card->dev, "AC'97 space ioremap problem\n"); - snd_atiixp_free(chip); - return -EIO; - } + chip->remap_addr = pcim_iomap_table(pci)[0]; - if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED, - KBUILD_MODNAME, chip)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_atiixp_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_atiixp_free(chip); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; + card->private_free = snd_atiixp_free; pci_set_master(pci); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_atiixp_free(chip); - return err; - } - - *r_chip = chip; return 0; } @@ -1622,30 +1579,31 @@ static int snd_atiixp_probe(struct pci_dev *pci, struct atiixp *chip; int err; - err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA"); strcpy(card->shortname, "ATI IXP"); - err = snd_atiixp_create(card, pci, &chip); + err = snd_atiixp_init(card, pci); if (err < 0) - goto __error; - card->private_data = chip; + return err; err = snd_atiixp_aclink_reset(chip); if (err < 0) - goto __error; + return err; chip->spdif_over_aclink = spdif_aclink; err = snd_atiixp_mixer_new(chip, ac97_clock, ac97_quirk); if (err < 0) - goto __error; + return err; err = snd_atiixp_pcm_new(chip); if (err < 0) - goto __error; + return err; snd_atiixp_proc_init(chip); @@ -1659,26 +1617,16 @@ static int snd_atiixp_probe(struct pci_dev *pci, err = snd_card_register(card); if (err < 0) - goto __error; + return err; pci_set_drvdata(pci, card); return 0; - - __error: - snd_card_free(card); - return err; -} - -static void snd_atiixp_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); } static struct pci_driver atiixp_driver = { .name = KBUILD_MODNAME, .id_table = snd_atiixp_ids, .probe = snd_atiixp_probe, - .remove = snd_atiixp_remove, .driver = { .pm = SND_ATIIXP_PM_OPS, }, diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c index 9739c3a82777..178dce8ef1e9 100644 --- a/sound/pci/atiixp_modem.c +++ b/sound/pci/atiixp_modem.c @@ -1159,87 +1159,44 @@ static void snd_atiixp_proc_init(struct atiixp_modem *chip) * destructor */ -static int snd_atiixp_free(struct atiixp_modem *chip) +static void snd_atiixp_free(struct snd_card *card) { - if (chip->irq < 0) - goto __hw_end; - snd_atiixp_chip_stop(chip); - - __hw_end: - if (chip->irq >= 0) - free_irq(chip->irq, chip); - iounmap(chip->remap_addr); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; -} - -static int snd_atiixp_dev_free(struct snd_device *device) -{ - struct atiixp_modem *chip = device->device_data; - return snd_atiixp_free(chip); + snd_atiixp_chip_stop(card->private_data); } /* * constructor for chip instance */ -static int snd_atiixp_create(struct snd_card *card, - struct pci_dev *pci, - struct atiixp_modem **r_chip) +static int snd_atiixp_init(struct snd_card *card, struct pci_dev *pci) { - static const struct snd_device_ops ops = { - .dev_free = snd_atiixp_dev_free, - }; - struct atiixp_modem *chip; + struct atiixp_modem *chip = card->private_data; int err; - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } - spin_lock_init(&chip->reg_lock); mutex_init(&chip->open_mutex); chip->card = card; chip->pci = pci; chip->irq = -1; - err = pci_request_regions(pci, "ATI IXP MC97"); - if (err < 0) { - kfree(chip); - pci_disable_device(pci); + err = pcim_iomap_regions(pci, 1 << 0, "ATI IXP MC97"); + if (err < 0) return err; - } chip->addr = pci_resource_start(pci, 0); - chip->remap_addr = pci_ioremap_bar(pci, 0); - if (chip->remap_addr == NULL) { - dev_err(card->dev, "AC'97 space ioremap problem\n"); - snd_atiixp_free(chip); - return -EIO; - } + chip->remap_addr = pcim_iomap_table(pci)[0]; - if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED, - KBUILD_MODNAME, chip)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_atiixp_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_atiixp_free(chip); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; + card->private_free = snd_atiixp_free; pci_set_master(pci); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_atiixp_free(chip); - return err; - } - - *r_chip = chip; return 0; } @@ -1251,28 +1208,29 @@ static int snd_atiixp_probe(struct pci_dev *pci, struct atiixp_modem *chip; int err; - err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; strcpy(card->driver, "ATIIXP-MODEM"); strcpy(card->shortname, "ATI IXP Modem"); - err = snd_atiixp_create(card, pci, &chip); + err = snd_atiixp_init(card, pci); if (err < 0) - goto __error; - card->private_data = chip; + return err; err = snd_atiixp_aclink_reset(chip); if (err < 0) - goto __error; + return err; err = snd_atiixp_mixer_new(chip, ac97_clock); if (err < 0) - goto __error; + return err; err = snd_atiixp_pcm_new(chip); if (err < 0) - goto __error; + return err; snd_atiixp_proc_init(chip); @@ -1283,26 +1241,16 @@ static int snd_atiixp_probe(struct pci_dev *pci, err = snd_card_register(card); if (err < 0) - goto __error; + return err; pci_set_drvdata(pci, card); return 0; - - __error: - snd_card_free(card); - return err; -} - -static void snd_atiixp_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); } static struct pci_driver atiixp_modem_driver = { .name = KBUILD_MODNAME, .id_table = snd_atiixp_ids, .probe = snd_atiixp_probe, - .remove = snd_atiixp_remove, .driver = { .pm = SND_ATIIXP_PM_OPS, }, From patchwork Tue Jul 13 14:24:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474738 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=-18.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, USER_AGENT_GIT 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 82DECC07E95 for ; Tue, 13 Jul 2021 14:29:21 +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 0373C610A7 for ; Tue, 13 Jul 2021 14:29:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0373C610A7 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 9287B16C9; Tue, 13 Jul 2021 16:28:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9287B16C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186559; bh=dygp7l9dRjraYxuO8M6a3srDZkTC+yzU5SZoKKwqOQM=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TGr8hSbMURPiTaZ+5xD4cRannWGnvxAGq3NtYX2B8R6mcn5BxrsR7rHcOzyOR1h5y F84nzJDDkk7iOmrpAgm+Va72K9he9c9jwmfHOq+aZfXfUntFLtpT9f0rppp3YS2Brb TAJG98nusB8dbsMdRDm5HbVAF47IT/LPsYhLX7AA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C364CF8051C; Tue, 13 Jul 2021 16:25:18 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 75A9AF804F2; Tue, 13 Jul 2021 16:25:13 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 277C4F80430 for ; Tue, 13 Jul 2021 16:24:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 277C4F80430 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="RWRw74N/"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Rne7O6+X" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0AC3B228F2 for ; Tue, 13 Jul 2021 14:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kujywtrM7C2dS+YRTuwBHd2FutC2YUFWonnKVXTOTg4=; b=RWRw74N/FmvVN+hjPZvA8l84inzm4kZMI67HMCFLL5eDihgcc78Pa7P5NArYKz03yRTiF3 knXkS/rdB6tC1/YldxxeRJkony0sDO+82k0xEECqPD0+b+l28mq5avH/h2ByYWAAYH2BXu 6qK16fiJ7SA65DEo4YzCVbJmyTOoAMQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kujywtrM7C2dS+YRTuwBHd2FutC2YUFWonnKVXTOTg4=; b=Rne7O6+Xdy0+7KhWerdn/7WqGk15IdzRNoCbomd5H/gLhyaAXzMVisuJdtX+kkNEOgmdjx KHRV9iIIBAcPTCAA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 0463AA3B8C; Tue, 13 Jul 2021 14:24:55 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 05/51] ALSA: hda: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:24:41 +0200 Message-Id: <20210713142445.19252-6-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142445.19252-1-tiwai@suse.de> References: <20210713142445.19252-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch is an attempt to slightly simplify the resource management in HD-audio code, by using some device-managed APIs. Only a few resources like PCI enablement and PCI resources managed via devres, but most of the rest code dealing with HD-audio core stuff couldn't be changed so much, hence the changes in this patch are pretty small in the end. A special caveat is needed for the card object: we can't move the card object release into devres, because the driver is involved with the component stuff and its unregistiration doesn't work well from devres release at all. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_controller.h | 1 - sound/pci/hda/hda_intel.c | 26 +++++--------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/sound/pci/hda/hda_controller.h b/sound/pci/hda/hda_controller.h index 68f9668788ea..e4b290de81de 100644 --- a/sound/pci/hda/hda_controller.h +++ b/sound/pci/hda/hda_controller.h @@ -141,7 +141,6 @@ struct azx { unsigned int snoop:1; unsigned int uc_buffer:1; /* non-cached pages for stream buffers */ unsigned int align_buffer_size:1; - unsigned int region_requested:1; unsigned int disabled:1; /* disabled by vga_switcheroo */ unsigned int pm_prepared:1; diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 0322b289505e..4d64f2ce30dc 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c @@ -1367,18 +1367,11 @@ static void azx_free(struct azx *chip) if (bus->irq >= 0) free_irq(bus->irq, (void*)chip); - if (chip->msi) - pci_disable_msi(chip->pci); - iounmap(bus->remap_addr); azx_free_stream_pages(chip); azx_free_streams(chip); snd_hdac_bus_exit(bus); - if (chip->region_requested) - pci_release_regions(chip->pci); - - pci_disable_device(chip->pci); #ifdef CONFIG_SND_HDA_PATCH_LOADER release_firmware(chip->fw); #endif @@ -1767,15 +1760,13 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, *rchip = NULL; - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; hda = devm_kzalloc(&pci->dev, sizeof(*hda), GFP_KERNEL); - if (!hda) { - pci_disable_device(pci); + if (!hda) return -ENOMEM; - } chip = &hda->chip; mutex_init(&chip->open_mutex); @@ -1811,10 +1802,8 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci, chip->bdl_pos_adj = bdl_pos_adj[dev]; err = azx_bus_init(chip, model[dev]); - if (err < 0) { - pci_disable_device(pci); + if (err < 0) return err; - } /* use the non-cached pages in non-snoop mode */ if (!azx_snoop(chip)) @@ -1860,17 +1849,12 @@ static int azx_first_init(struct azx *chip) } #endif - err = pci_request_regions(pci, "ICH HD audio"); + err = pcim_iomap_regions(pci, 1 << 0, "ICH HD audio"); if (err < 0) return err; - chip->region_requested = 1; bus->addr = pci_resource_start(pci, 0); - bus->remap_addr = pci_ioremap_bar(pci, 0); - if (bus->remap_addr == NULL) { - dev_err(card->dev, "ioremap error\n"); - return -ENXIO; - } + bus->remap_addr = pcim_iomap_table(pci)[0]; if (chip->driver_type == AZX_DRIVER_SKL) snd_hdac_bus_parse_capabilities(bus); From patchwork Tue Jul 13 14:24:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474739 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=-16.0 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, UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT 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 70522C07E95 for ; Tue, 13 Jul 2021 14:28:30 +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 E14E061026 for ; Tue, 13 Jul 2021 14:28:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E14E061026 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 7C48C16AC; Tue, 13 Jul 2021 16:27:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7C48C16AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186508; bh=u0r0MMcEXuzys7gB+r1poMB/JHK06NbQ41Atw2AjXvI=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=braJ52v3S2msJvV/T388UdMovLhsR/9w7k0XYYgk5TJK52g/kpMi1YSO7tUO4Cg8s wHXUUnN01K1K5qZtgXKL9yJdWHQkVtCFgzSfnSxaWWs5QwOBfCzsyhy1AkJYOBuOCB dCW+wIII/zzhKxsMxYo5B+5o2wd9Um1w8hWqeBsc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AD8F1F804FF; Tue, 13 Jul 2021 16:25:16 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9443AF802E0; Tue, 13 Jul 2021 16:25:11 +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 048E1F80229 for ; Tue, 13 Jul 2021 16:24:55 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 048E1F80229 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="NKk6D68r"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="big7pSCA" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 26B8E201E5 for ; Tue, 13 Jul 2021 14:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8pc2c6upT4f/IawpfVgQ9TB9w3B6L3EC07I8Ldp8lY=; b=NKk6D68rEKViM+OyVBpisOsDVK7yHDrZRTyGRtjmG20cxCTwV1bf/+2NL/5KqAaSY20GlE T7T6p7nlpfHVwOHRbmffjJZxetUt1ww1I+UYfh2RERqRBlXR/vdlcpi88NbVWnhU9BWpsf 4qhMcIgPVFRpmLOzCO/SoSbcpY4C/pk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186295; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8pc2c6upT4f/IawpfVgQ9TB9w3B6L3EC07I8Ldp8lY=; b=big7pSCAIa3YySRt6lGvv1i7yAiyuxL2e2fQ3pk6P88u/SKXt2nxupV6LfJVdl8B1viykO ApnFbp4wvuenAeCA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 16168A3B88; Tue, 13 Jul 2021 14:24:55 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 07/51] ALSA: ad1889: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:24:43 +0200 Message-Id: <20210713142445.19252-8-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142445.19252-1-tiwai@suse.de> References: <20210713142445.19252-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI ad1889 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. Also, the unnecessary ac97 free callbacks are removed, too. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/pci/ad1889.c | 144 ++++++++------------------------------------- 1 file changed, 25 insertions(+), 119 deletions(-) diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c index 5c78951dd596..bba4dae8dcc7 100644 --- a/sound/pci/ad1889.c +++ b/sound/pci/ad1889.c @@ -740,20 +740,6 @@ snd_ad1889_ac97_xinit(struct snd_ad1889 *chip) } -static void -snd_ad1889_ac97_bus_free(struct snd_ac97_bus *bus) -{ - struct snd_ad1889 *chip = bus->private_data; - chip->ac97_bus = NULL; -} - -static void -snd_ad1889_ac97_free(struct snd_ac97 *ac97) -{ - struct snd_ad1889 *chip = ac97->private_data; - chip->ac97 = NULL; -} - static int snd_ad1889_ac97_init(struct snd_ad1889 *chip, const char *quirk_override) { @@ -771,11 +757,8 @@ snd_ad1889_ac97_init(struct snd_ad1889 *chip, const char *quirk_override) if (err < 0) return err; - chip->ac97_bus->private_free = snd_ad1889_ac97_bus_free; - memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; - ac97.private_free = snd_ad1889_ac97_free; ac97.pci = chip->pci; err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); @@ -787,11 +770,10 @@ snd_ad1889_ac97_init(struct snd_ad1889 *chip, const char *quirk_override) return 0; } -static int -snd_ad1889_free(struct snd_ad1889 *chip) +static void +snd_ad1889_free(struct snd_card *card) { - if (chip->irq < 0) - goto skip_hw; + struct snd_ad1889 *chip = card->private_data; spin_lock_irq(&chip->lock); @@ -805,125 +787,60 @@ snd_ad1889_free(struct snd_ad1889 *chip) ad1889_readl(chip, AD_DMA_DISR); /* flush, dammit! */ spin_unlock_irq(&chip->lock); - - if (chip->irq >= 0) - free_irq(chip->irq, chip); - -skip_hw: - iounmap(chip->iobase); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; -} - -static int -snd_ad1889_dev_free(struct snd_device *device) -{ - struct snd_ad1889 *chip = device->device_data; - return snd_ad1889_free(chip); -} - -static int -snd_ad1889_init(struct snd_ad1889 *chip) -{ - ad1889_writew(chip, AD_DS_CCS, AD_DS_CCS_CLKEN); /* turn on clock */ - ad1889_readw(chip, AD_DS_CCS); /* flush posted write */ - - usleep_range(10000, 11000); - - /* enable Master and Target abort interrupts */ - ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PMAE | AD_DMA_DISR_PTAE); - - return 0; } static int -snd_ad1889_create(struct snd_card *card, - struct pci_dev *pci, - struct snd_ad1889 **rchip) +snd_ad1889_create(struct snd_card *card, struct pci_dev *pci) { + struct snd_ad1889 *chip = card->private_data; int err; - struct snd_ad1889 *chip; - static const struct snd_device_ops ops = { - .dev_free = snd_ad1889_dev_free, - }; - - *rchip = NULL; - - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; /* check PCI availability (32bit DMA) */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32))) { dev_err(card->dev, "error setting 32-bit DMA mask.\n"); - pci_disable_device(pci); return -ENXIO; } - /* allocate chip specific data with zero-filled memory */ - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (!chip) { - pci_disable_device(pci); - return -ENOMEM; - } - chip->card = card; - card->private_data = chip; chip->pci = pci; chip->irq = -1; /* (1) PCI resource allocation */ - err = pci_request_regions(pci, card->driver); + err = pcim_iomap_regions(pci, 1 << 0, card->driver); if (err < 0) - goto free_and_ret; + return err; chip->bar = pci_resource_start(pci, 0); - chip->iobase = pci_ioremap_bar(pci, 0); - if (chip->iobase == NULL) { - dev_err(card->dev, "unable to reserve region.\n"); - err = -EBUSY; - goto free_and_ret; - } + chip->iobase = pcim_iomap_table(pci)[0]; pci_set_master(pci); spin_lock_init(&chip->lock); /* only now can we call ad1889_free */ - if (request_irq(pci->irq, snd_ad1889_interrupt, - IRQF_SHARED, KBUILD_MODNAME, chip)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_ad1889_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "cannot obtain IRQ %d\n", pci->irq); - snd_ad1889_free(chip); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; + card->private_free = snd_ad1889_free; /* (2) initialization of the chip hardware */ - err = snd_ad1889_init(chip); - if (err < 0) { - snd_ad1889_free(chip); - return err; - } + ad1889_writew(chip, AD_DS_CCS, AD_DS_CCS_CLKEN); /* turn on clock */ + ad1889_readw(chip, AD_DS_CCS); /* flush posted write */ - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_ad1889_free(chip); - return err; - } + usleep_range(10000, 11000); - *rchip = chip; + /* enable Master and Target abort interrupts */ + ad1889_writel(chip, AD_DMA_DISR, AD_DMA_DISR_PMAE | AD_DMA_DISR_PTAE); return 0; - -free_and_ret: - kfree(chip); - pci_disable_device(pci); - - return err; } static int @@ -944,19 +861,19 @@ snd_ad1889_probe(struct pci_dev *pci, } /* (2) */ - err = snd_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE, - 0, &card); - /* XXX REVISIT: we can probably allocate chip in this call */ + err = snd_devm_card_new(&pci->dev, index[devno], id[devno], THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; strcpy(card->driver, "AD1889"); strcpy(card->shortname, "Analog Devices AD1889"); /* (3) */ - err = snd_ad1889_create(card, pci, &chip); + err = snd_ad1889_create(card, pci); if (err < 0) - goto free_and_ret; + return err; /* (4) */ sprintf(card->longname, "%s at 0x%lx irq %i", @@ -966,11 +883,11 @@ snd_ad1889_probe(struct pci_dev *pci, /* register AC97 mixer */ err = snd_ad1889_ac97_init(chip, ac97_quirk[devno]); if (err < 0) - goto free_and_ret; + return err; err = snd_ad1889_pcm_init(chip, 0); if (err < 0) - goto free_and_ret; + return err; /* register proc interface */ snd_ad1889_proc_init(chip); @@ -978,23 +895,13 @@ snd_ad1889_probe(struct pci_dev *pci, /* (6) */ err = snd_card_register(card); if (err < 0) - goto free_and_ret; + return err; /* (7) */ pci_set_drvdata(pci, card); devno++; return 0; - -free_and_ret: - snd_card_free(card); - return err; -} - -static void -snd_ad1889_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); } static const struct pci_device_id snd_ad1889_ids[] = { @@ -1007,7 +914,6 @@ static struct pci_driver ad1889_pci_driver = { .name = KBUILD_MODNAME, .id_table = snd_ad1889_ids, .probe = snd_ad1889_probe, - .remove = snd_ad1889_remove, }; module_pci_driver(ad1889_pci_driver); From patchwork Tue Jul 13 14:28:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474735 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=-18.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, USER_AGENT_GIT 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 7F010C07E95 for ; Tue, 13 Jul 2021 14:32:42 +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 A89E8610C7 for ; Tue, 13 Jul 2021 14:32:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A89E8610C7 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 495EC1681; Tue, 13 Jul 2021 16:31:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 495EC1681 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186760; bh=Sgyr/28/hWi3iqXKf4RMHJdDGR7248SaE8ju4gupa08=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=e0RV6VHKJ2N6nuDPh+OIwnEveLLwrw9feFPwTVYACN6LgnrbP62N/rvO4PMapo1BE DbUSL1ZUntsj7pfqDnU0nJArYZVvfrSZ6/KapEuI5p05HKjEgMF539csf7Ep4VclPe r+Q7l5X2FKHAar5VoAsVti/NhWKTwDG4tK53x2LI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 03BF7F804E3; Tue, 13 Jul 2021 16:29:40 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2E33DF80511; Tue, 13 Jul 2021 16:29:23 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 0016DF804F3 for ; Tue, 13 Jul 2021 16:29:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0016DF804F3 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ch3Vm+tI"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="NFmxaVA9" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 92A0322855 for ; Tue, 13 Jul 2021 14:29:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186555; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i31mm3UNYG7ksKe/S6D/uXkcvMfW/Lx8iyy2EJ3/ez8=; b=ch3Vm+tIWG6s2EOsEU3fApSEGqL4FIIom+/LWrMn3thpCmhX1JR4xQ96Jk+2XTncdU8Axz z0cAHC8kxQFp4X16O1j1pJRKXGvFZY5s9tSfLZTgHZeyE2MamQvnBjlW+u/fV1VyyCVcyq Su5o0Pg5ORWZDyCX5I6R08VO18d4zJg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186555; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i31mm3UNYG7ksKe/S6D/uXkcvMfW/Lx8iyy2EJ3/ez8=; b=NFmxaVA9hmdGogbGqslGwAjkfZQScheZuQ071mb5TSLHajA0hWIP0aqVmK4rGPR/GTsUFJ DOeOXOlIGV4MJzAg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 82276A3B90; Tue, 13 Jul 2021 14:29:15 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 08/51] ALSA: als300: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:14 +0200 Message-Id: <20210713142857.19654-9-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" 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) @@ -764,10 +721,9 @@ static int snd_als300_probe(struct pci_dev *pci, card->shortname, chip->port, chip->irq); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } + pci_set_drvdata(pci, card); dev++; return 0; @@ -777,7 +733,6 @@ static struct pci_driver als300_driver = { .name = KBUILD_MODNAME, .id_table = snd_als300_ids, .probe = snd_als300_probe, - .remove = snd_als300_remove, .driver = { .pm = SND_ALS300_PM_OPS, }, From patchwork Tue Jul 13 14:28:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474732 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=-18.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, USER_AGENT_GIT 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 DB223C07E95 for ; Tue, 13 Jul 2021 14:34:42 +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 57793610CB for ; Tue, 13 Jul 2021 14:34:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 57793610CB 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 C19D31710; Tue, 13 Jul 2021 16:33:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C19D31710 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186880; bh=iL+5QYWcqFJ/rqVbv6HLHKqK9CLp3bE/Iik22OwQ83w=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SiDrj/ywSdaZpOEuc7RoBGEvEmDeL9fsp2EZDEpZYLBBN/5Hkxe44uq236XQBk6Hi +p5/fA5LQfuzKZbCASZ2KDEeabn2f2qsRfSVaYHxVMWl2AcFo9WhqRh9KnAA3zuB1+ BDT+1M1fs8lsC2LXOMkcVKBuusXyr6q7AgbLcAhs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 5DAD0F8056F; Tue, 13 Jul 2021 16:29:49 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 47B77F8051D; Tue, 13 Jul 2021 16:29:32 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 670EAF8020C for ; Tue, 13 Jul 2021 16:29:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 670EAF8020C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="ipJlu2G3"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="kNEenyJP" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 70A4B22890 for ; Tue, 13 Jul 2021 14:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186556; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nl60tUDaTiqUjJ7wQbcQb591DUGCv849os2WeQHxgc8=; b=ipJlu2G338IFwFUnYS5XuPwhK8hAB7DEW6ZVnZXQMSxKANM+qPznOAq1o0ZL0N4cvnAA0k j94CFaNyGDVNHTR/8ipgSFwoBgyqonwtNIsapt0d4aDv4vtEDMc74e9PkOexNF9A75VHqA vtk4ZSVqqPvLeO3vi8Jjl4osIA6oNSc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186556; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nl60tUDaTiqUjJ7wQbcQb591DUGCv849os2WeQHxgc8=; b=kNEenyJPNkCMuuhjIQ7wjzq9XwuGQdDYGMhDGUq8TXoOR3GW8F/0xwrfYFu9DvrAo6t/Jv 4qfQ3WffxmSgUFBA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 69637A3B85; Tue, 13 Jul 2021 14:29:16 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 09/51] ALSA: als4000: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:15 +0200 Message-Id: <20210713142857.19654-10-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI als4000 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/als4000.c | 59 +++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c index 509f317ee682..535eccd124be 100644 --- a/sound/pci/als4000.c +++ b/sound/pci/als4000.c @@ -746,13 +746,15 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) if (joystick_port[dev] == 1) { /* auto-detect */ for (io_port = 0x200; io_port <= 0x218; io_port += 8) { - r = request_region(io_port, 8, "ALS4000 gameport"); + r = devm_request_region(&acard->pci->dev, io_port, 8, + "ALS4000 gameport"); if (r) break; } } else { io_port = joystick_port[dev]; - r = request_region(io_port, 8, "ALS4000 gameport"); + r = devm_request_region(&acard->pci->dev, io_port, 8, + "ALS4000 gameport"); } if (!r) { @@ -763,7 +765,6 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) acard->gameport = gp = gameport_allocate_port(); if (!gp) { dev_err(&acard->pci->dev, "cannot allocate memory for gameport\n"); - release_and_free_resource(r); return -ENOMEM; } @@ -771,7 +772,6 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) gameport_set_phys(gp, "pci%s/gameport0", pci_name(acard->pci)); gameport_set_dev_parent(gp, &acard->pci->dev); gp->io = io_port; - gameport_set_port_data(gp, r); /* Enable legacy joystick port */ snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1); @@ -784,15 +784,11 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) static void snd_als4000_free_gameport(struct snd_card_als4000 *acard) { if (acard->gameport) { - struct resource *r = gameport_get_port_data(acard->gameport); - gameport_unregister_port(acard->gameport); acard->gameport = NULL; /* disable joystick */ snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0); - - release_and_free_resource(r); } } #else @@ -808,8 +804,6 @@ static void snd_card_als4000_free( struct snd_card *card ) snd_als4k_gcr_write_addr(acard->iobase, ALS4K_GCR8C_MISC_CTRL, 0); /* free resources */ snd_als4000_free_gameport(acard); - pci_release_regions(acard->pci); - pci_disable_device(acard->pci); } static int snd_card_als4000_probe(struct pci_dev *pci, @@ -832,36 +826,30 @@ static int snd_card_als4000_probe(struct pci_dev *pci, } /* enable PCI device */ - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; /* check, if we can restrict PCI DMA transfers to 24 bits */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n"); - pci_disable_device(pci); return -ENXIO; } err = pci_request_regions(pci, "ALS4000"); - if (err < 0) { - pci_disable_device(pci); + if (err < 0) return err; - } iobase = pci_resource_start(pci, 0); pci_read_config_word(pci, PCI_COMMAND, &word); pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO); pci_set_master(pci); - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, - sizeof(*acard) /* private_data: acard */, - &card); - if (err < 0) { - pci_release_regions(pci); - pci_disable_device(pci); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, + sizeof(*acard) /* private_data: acard */, + &card); + if (err < 0) return err; - } acard = card->private_data; acard->pci = pci; @@ -881,7 +869,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci, SB_HW_ALS4000, &chip); if (err < 0) - goto out_err; + return err; acard->chip = chip; chip->pci = pci; @@ -902,7 +890,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci, if (err < 0) { dev_err(&pci->dev, "no MPU-401 device at 0x%lx?\n", iobase + ALS4K_IOB_30_MIDI_DATA); - goto out_err; + return err; } /* FIXME: ALS4000 has interesting MPU401 configuration features * at ALS4K_CR1A_MPU401_UART_MODE_CONTROL @@ -912,11 +900,11 @@ static int snd_card_als4000_probe(struct pci_dev *pci, err = snd_als4000_pcm(chip, 0); if (err < 0) - goto out_err; + return err; err = snd_sbmixer_new(chip); if (err < 0) - goto out_err; + return err; if (snd_opl3_create(card, iobase + ALS4K_IOB_10_ADLIB_ADDR0, @@ -928,30 +916,18 @@ static int snd_card_als4000_probe(struct pci_dev *pci, } else { err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); if (err < 0) - goto out_err; + return err; } snd_als4000_create_gameport(acard, dev); err = snd_card_register(card); if (err < 0) - goto out_err; + return err; pci_set_drvdata(pci, card); dev++; - err = 0; - goto out; - -out_err: - snd_card_free(card); - -out: - return err; -} - -static void snd_card_als4000_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); + return 0; } #ifdef CONFIG_PM_SLEEP @@ -996,7 +972,6 @@ static struct pci_driver als4000_driver = { .name = KBUILD_MODNAME, .id_table = snd_als4000_ids, .probe = snd_card_als4000_probe, - .remove = snd_card_als4000_remove, .driver = { .pm = SND_ALS4000_PM_OPS, }, From patchwork Tue Jul 13 14:28:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474733 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=-18.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, USER_AGENT_GIT 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 C10D7C07E95 for ; Tue, 13 Jul 2021 14:34:02 +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 50CA8610CB for ; Tue, 13 Jul 2021 14:34:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50CA8610CB 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 DB96E1708; Tue, 13 Jul 2021 16:33:10 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DB96E1708 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186840; bh=0CHq83icnk0lyM3pxrlCAd8K+/mSoHI/DB7w6Nb0DpE=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=bMZ3xKvlqpzW8eNEsqiD49QpcLTZlrRhqsDx7lNa1ZSZt6VTKmtL5sFcnrWWlQ0VG K/JMSVnWlhAOs1oroKjtjCbp2dl3hHhhRbrK6Xxh7f17Z98eX8n8HgLQIQCWroWJY2 XByjcldZ6XdPbcDyQcVzdJpP+r14vWsDifsWK/2E= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 49713F80558; Tue, 13 Jul 2021 16:29:46 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4C70AF80526; Tue, 13 Jul 2021 16:29:30 +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 DA690F804FC for ; Tue, 13 Jul 2021 16:29:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DA690F804FC Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="cwOiDTLE"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XsVED/Dt" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id AB9F8201DA for ; Tue, 13 Jul 2021 14:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186557; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ur5TcnpNUht5hJjxu5Icx9JkyUj2FHX6R1MyuDkEkcc=; b=cwOiDTLEDk7eaV25pjnca43jRBJW0s0Feo8Rt/cQBRd7IC8nfL0JEXW5DHIs9R7jteptWy S7Lhf1v0huNhO23dt07KghfiXhJ5F3VWO7PDTm9MAjjY+F0MQLOI5CmF6UbPeCjduILbL8 dAjj6Ew1Fr2E4FGOfE7iJtihIXGwW1E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186557; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ur5TcnpNUht5hJjxu5Icx9JkyUj2FHX6R1MyuDkEkcc=; b=XsVED/Dtgg0m1UH0FZMdzQuDo/BbUR1gTO0tqYT7s9cYPj1J6hJxKP93CB1tBVgFa7PGs7 6tblZJiXa0pCqZCw== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 9A052A3B85; Tue, 13 Jul 2021 14:29:17 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 10/51] ALSA: azt3328: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:16 +0200 Message-Id: <20210713142857.19654-11-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI azt3328 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/azt3328.c | 124 +++++++++++--------------------------------- 1 file changed, 30 insertions(+), 94 deletions(-) diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c index 4ee7ab409807..089050470ff2 100644 --- a/sound/pci/azt3328.c +++ b/sound/pci/azt3328.c @@ -2244,32 +2244,15 @@ snd_azf3328_timer(struct snd_azf3328 *chip, int device) /******************************************************************/ -static int -snd_azf3328_free(struct snd_azf3328 *chip) +static void +snd_azf3328_free(struct snd_card *card) { - if (chip->irq < 0) - goto __end_hw; + struct snd_azf3328 *chip = card->private_data; snd_azf3328_mixer_reset(chip); snd_azf3328_timer_stop(chip->timer); snd_azf3328_gameport_free(chip); - -__end_hw: - if (chip->irq >= 0) - free_irq(chip->irq, chip); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - - kfree(chip); - return 0; -} - -static int -snd_azf3328_dev_free(struct snd_device *device) -{ - struct snd_azf3328 *chip = device->device_data; - return snd_azf3328_free(chip); } #if 0 @@ -2350,29 +2333,18 @@ snd_azf3328_debug_show_ports(const struct snd_azf3328 *chip) static int snd_azf3328_create(struct snd_card *card, struct pci_dev *pci, - unsigned long device_type, - struct snd_azf3328 **rchip) + unsigned long device_type) { - struct snd_azf3328 *chip; + struct snd_azf3328 *chip = card->private_data; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_azf3328_dev_free, - }; u8 dma_init; enum snd_azf3328_codec_type codec_type; struct snd_azf3328_codec_data *codec_setup; - *rchip = NULL; - - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - err = -ENOMEM; - goto out_err; - } spin_lock_init(&chip->reg_lock); chip->card = card; chip->pci = pci; @@ -2383,13 +2355,12 @@ snd_azf3328_create(struct snd_card *card, dev_err(card->dev, "architecture does not support 24bit PCI busmaster DMA\n" ); - err = -ENXIO; - goto out_err; + return -ENXIO; } err = pci_request_regions(pci, "Aztech AZF3328"); if (err < 0) - goto out_err; + return err; chip->ctrl_io = pci_resource_start(pci, 0); chip->game_io = pci_resource_start(pci, 1); @@ -2415,26 +2386,22 @@ snd_azf3328_create(struct snd_card *card, codec_setup->type = AZF_CODEC_I2S_OUT; codec_setup->name = "I2S_OUT"; - if (request_irq(pci->irq, snd_azf3328_interrupt, - IRQF_SHARED, KBUILD_MODNAME, chip)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_azf3328_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - err = -EBUSY; - goto out_err; + return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; + card->private_free = snd_azf3328_free; pci_set_master(pci); snd_azf3328_debug_show_ports(chip); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) - goto out_err; - /* create mixer interface & switches */ err = snd_azf3328_mixer_new(chip); if (err < 0) - goto out_err; + return err; /* standard codec init stuff */ /* default DMA init value */ @@ -2456,18 +2423,7 @@ snd_azf3328_create(struct snd_card *card, spin_unlock_irq(codec->lock); } - *rchip = chip; - - err = 0; - goto out; - -out_err: - if (chip) - snd_azf3328_free(chip); - pci_disable_device(pci); - -out: - return err; + return 0; } static int @@ -2479,29 +2435,25 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) struct snd_opl3 *opl3; int err; - if (dev >= SNDRV_CARDS) { - err = -ENODEV; - goto out; - } + if (dev >= SNDRV_CARDS) + return -ENODEV; if (!enable[dev]) { dev++; - err = -ENOENT; - goto out; + 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) - goto out; + return err; + chip = card->private_data; strcpy(card->driver, "AZF3328"); strcpy(card->shortname, "Aztech AZF3328 (PCI168)"); - err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip); + err = snd_azf3328_create(card, pci, pci_id->driver_data); if (err < 0) - goto out_err; - - card->private_data = chip; + return err; /* chose to use MPU401_HW_AZT2320 ID instead of MPU401_HW_MPU401, since our hardware ought to be similar, thus use same ID. */ @@ -2515,16 +2467,16 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) dev_err(card->dev, "no MPU-401 device at 0x%lx?\n", chip->mpu_io ); - goto out_err; + return err; } err = snd_azf3328_timer(chip, 0); if (err < 0) - goto out_err; + return err; err = snd_azf3328_pcm(chip); if (err < 0) - goto out_err; + return err; if (snd_opl3_create(card, chip->opl3_io, chip->opl3_io+2, OPL3_HW_AUTO, 1, &opl3) < 0) { @@ -2535,10 +2487,10 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) /* need to use IDs 1, 2 since ID 0 is snd_azf3328_timer above */ err = snd_opl3_timer_new(opl3, 1, 2); if (err < 0) - goto out_err; + return err; err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); if (err < 0) - goto out_err; + return err; opl3->private_data = chip; } @@ -2547,7 +2499,7 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) err = snd_card_register(card); if (err < 0) - goto out_err; + return err; #ifdef MODULE dev_info(card->dev, @@ -2565,22 +2517,7 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) pci_set_drvdata(pci, card); dev++; - - err = 0; - goto out; - -out_err: - dev_err(card->dev, "something failed, exiting\n"); - snd_card_free(card); - -out: - return err; -} - -static void -snd_azf3328_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); + return 0; } #ifdef CONFIG_PM_SLEEP @@ -2709,7 +2646,6 @@ static struct pci_driver azf3328_driver = { .name = KBUILD_MODNAME, .id_table = snd_azf3328_ids, .probe = snd_azf3328_probe, - .remove = snd_azf3328_remove, .driver = { .pm = SND_AZF3328_PM_OPS, }, From patchwork Tue Jul 13 14:28:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474731 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=-18.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, USER_AGENT_GIT 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 971ACC07E95 for ; Tue, 13 Jul 2021 14:35:22 +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 2363C610CB for ; Tue, 13 Jul 2021 14:35:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2363C610CB 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 B29471719; Tue, 13 Jul 2021 16:34:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B29471719 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186920; bh=lGOOa1LeFFqXu5p3eOQzB3Lhx77Ow0bafGxSaLuoAF8=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iW4ezXh/nbbeUlhqiBKyrRuXYmvIDPWd6SWtV5emgkzwnVmcb1EU0h8q9NyYKEDET OiiCaSFxIRYQnrhleTmsysPTybAvcEg4VZA6kOD19vfoOoy7fuIoT+LdGeI/sqU2SB ynAwazFPIKM3cJbFLpZ02Rr/nm5nEhR5rYvlt80w= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 7BD63F804FF; Tue, 13 Jul 2021 16:29:53 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 87A35F804E4; Tue, 13 Jul 2021 16:29:33 +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 AFFB3F804FF for ; Tue, 13 Jul 2021 16:29:20 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AFFB3F804FF Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Dm+yhYax"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Wwe6DnVp" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 887A9201E4 for ; Tue, 13 Jul 2021 14:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kKX4RzaGLOOByHQccy0gSPoAmPX6pLVoY4RclGH9Ado=; b=Dm+yhYaxzYQuR5IcFQygyp98RrecGbjUhkcQmgnwMBex1Q3P7rY7WJr8Eg/SnpHD9Bkpiu XkRQjmCj0WtMY++A+w2r4LO3DrAyfg610TBQOzfeKH8ShNV4+3KKEZZAqS5Hkp+YBhbEzu +9bxxNR9B1pX4auu/uoMdECz1ylzY4M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186560; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kKX4RzaGLOOByHQccy0gSPoAmPX6pLVoY4RclGH9Ado=; b=Wwe6DnVpcJCcQSGwI50gjPy0tmwQn89lbaMOnDuY+jmsNqvO2z9lT6c2V/FGLj5MnbPzEh di6Zp1hRf3jtgLDw== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 76A59A3B88; Tue, 13 Jul 2021 14:29:20 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 13/51] ALSA: cs4281: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:19 +0200 Message-Id: <20210713142857.19654-14-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI cs4281 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/cs4281.c | 112 ++++++++++----------------------------------- 1 file changed, 24 insertions(+), 88 deletions(-) diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c index e122a168c148..f338caf98354 100644 --- a/sound/pci/cs4281.c +++ b/sound/pci/cs4281.c @@ -1268,8 +1268,10 @@ static inline int snd_cs4281_create_gameport(struct cs4281 *chip) { return -ENOS static inline void snd_cs4281_free_gameport(struct cs4281 *chip) { } #endif /* IS_REACHABLE(CONFIG_GAMEPORT) */ -static int snd_cs4281_free(struct cs4281 *chip) +static void snd_cs4281_free(struct snd_card *card) { + struct cs4281 *chip = card->private_data; + snd_cs4281_free_gameport(chip); /* Mask interrupts */ @@ -1278,49 +1280,20 @@ static int snd_cs4281_free(struct cs4281 *chip) snd_cs4281_pokeBA0(chip, BA0_CLKCR1, 0); /* Sound System Power Management - Turn Everything OFF */ snd_cs4281_pokeBA0(chip, BA0_SSPM, 0); - /* PCI interface - D3 state */ - pci_set_power_state(chip->pci, PCI_D3hot); - - if (chip->irq >= 0) - free_irq(chip->irq, chip); - iounmap(chip->ba0); - iounmap(chip->ba1); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - - kfree(chip); - return 0; -} - -static int snd_cs4281_dev_free(struct snd_device *device) -{ - struct cs4281 *chip = device->device_data; - return snd_cs4281_free(chip); } static int snd_cs4281_chip_init(struct cs4281 *chip); /* defined below */ static int snd_cs4281_create(struct snd_card *card, struct pci_dev *pci, - struct cs4281 **rchip, int dual_codec) { struct cs4281 *chip; - unsigned int tmp; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_cs4281_dev_free, - }; - *rchip = NULL; - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } spin_lock_init(&chip->reg_lock); chip->card = card; chip->pci = pci; @@ -1332,46 +1305,29 @@ static int snd_cs4281_create(struct snd_card *card, } chip->dual_codec = dual_codec; - err = pci_request_regions(pci, "CS4281"); - if (err < 0) { - kfree(chip); - pci_disable_device(pci); + err = pcim_iomap_regions(pci, 0x03, "CS4281"); /* 2 BARs */ + if (err < 0) return err; - } chip->ba0_addr = pci_resource_start(pci, 0); chip->ba1_addr = pci_resource_start(pci, 1); - chip->ba0 = pci_ioremap_bar(pci, 0); - chip->ba1 = pci_ioremap_bar(pci, 1); - if (!chip->ba0 || !chip->ba1) { - snd_cs4281_free(chip); - return -ENOMEM; - } + chip->ba0 = pcim_iomap_table(pci)[0]; + chip->ba1 = pcim_iomap_table(pci)[1]; - if (request_irq(pci->irq, snd_cs4281_interrupt, IRQF_SHARED, - KBUILD_MODNAME, chip)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_cs4281_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_cs4281_free(chip); return -ENOMEM; } chip->irq = pci->irq; card->sync_irq = chip->irq; + card->private_free = snd_cs4281_free; - tmp = snd_cs4281_chip_init(chip); - if (tmp) { - snd_cs4281_free(chip); - return tmp; - } - - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_cs4281_free(chip); + err = snd_cs4281_chip_init(chip); + if (err) return err; - } snd_cs4281_proc_init(chip); - - *rchip = chip; return 0; } @@ -1887,46 +1843,34 @@ static int snd_cs4281_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 = card->private_data; - err = snd_cs4281_create(card, pci, &chip, dual_codec[dev]); - if (err < 0) { - snd_card_free(card); + err = snd_cs4281_create(card, pci, dual_codec[dev]); + if (err < 0) return err; - } - card->private_data = chip; err = snd_cs4281_mixer(chip); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_cs4281_pcm(chip, 0); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_cs4281_midi(chip, 0); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_opl3_new(card, OPL3_HW_OPL3_CS4281, &opl3); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } opl3->private_data = chip; opl3->command = snd_cs4281_opl3_command; snd_opl3_init(opl3); err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } snd_cs4281_create_gameport(chip); strcpy(card->driver, "CS4281"); strcpy(card->shortname, "Cirrus Logic CS4281"); @@ -1936,21 +1880,14 @@ static int snd_cs4281_probe(struct pci_dev *pci, chip->irq); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_cs4281_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - /* * Power Management */ @@ -2054,7 +1991,6 @@ static struct pci_driver cs4281_driver = { .name = KBUILD_MODNAME, .id_table = snd_cs4281_ids, .probe = snd_cs4281_probe, - .remove = snd_cs4281_remove, .driver = { .pm = CS4281_PM_OPS, }, From patchwork Tue Jul 13 14:28:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474730 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=-18.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, USER_AGENT_GIT 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 E7ECCC07E95 for ; Tue, 13 Jul 2021 14:36:09 +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 6EF25610D1 for ; Tue, 13 Jul 2021 14:36:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EF25610D1 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 035FB1716; Tue, 13 Jul 2021 16:35:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 035FB1716 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626186968; bh=DQC3G2XMkc7AsK5SEuBeyGUXU47UoamlJACL509eMwU=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TsMKkaVi4p7UOvcrHHmBr6I5yvcWWE/94gK8yP2HyOlncM2lbGMFMAknID5MoZT0p VS3xrZyZqBBe4uWIJDJYXQ7m0gj74nx12G0VsSTBwZUNTb6/dripYPfJTE3y2bfE/X fXfhY+nDn2OzQLs8vYpwxe74zH4enqrNxoxOihw4= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 26F21F80508; Tue, 13 Jul 2021 16:29:57 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1B68EF80431; Tue, 13 Jul 2021 16:29:36 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 7DC84F80508 for ; Tue, 13 Jul 2021 16:29:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7DC84F80508 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="p8fJDHWO"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="xDvE8s9Q" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4C93E22837 for ; Tue, 13 Jul 2021 14:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186561; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wNUmxcAtS4wVem+SPg7e0Sgp5Y/q4b/M/oRCZ/XAJ+c=; b=p8fJDHWOE4n1EgJ4ZrrK1x/EG6oH+CQWxLmbdYtHLn5KXUWklkf2tB9/pnpW/FKue/evRu dHtsZc0NMJdBO730tg0jIkEdu6GlKXOFSt6QEiyH5ZbBzzWhuRkIs/ZVLTgbb68cha8TmO oIyDTkTj4McIEGxipQVGraA2QvyyXYA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186561; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wNUmxcAtS4wVem+SPg7e0Sgp5Y/q4b/M/oRCZ/XAJ+c=; b=xDvE8s9QzcUxPzuhJfLemz+O7OfQTifM7d9e7m/9GoeNvPXpFnmAWTZ7LFuYbUdsZqN64q DUg/ccwiSVnQl/Ag== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 45E92A3B83; Tue, 13 Jul 2021 14:29:21 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 14/51] ALSA: cs5530: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:20 +0200 Message-Id: <20210713142857.19654-15-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI cs5530 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/cs5530.c | 86 +++++++--------------------------------------- 1 file changed, 13 insertions(+), 73 deletions(-) diff --git a/sound/pci/cs5530.c b/sound/pci/cs5530.c index 20b4faea50a6..93ff029e6583 100644 --- a/sound/pci/cs5530.c +++ b/sound/pci/cs5530.c @@ -65,25 +65,6 @@ static const struct pci_device_id snd_cs5530_ids[] = { MODULE_DEVICE_TABLE(pci, snd_cs5530_ids); -static int snd_cs5530_free(struct snd_cs5530 *chip) -{ - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; -} - -static int snd_cs5530_dev_free(struct snd_device *device) -{ - struct snd_cs5530 *chip = device->device_data; - return snd_cs5530_free(chip); -} - -static void snd_cs5530_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static u8 snd_cs5530_mixer_read(unsigned long io, u8 reg) { outb(reg, io + 4); @@ -94,50 +75,28 @@ static u8 snd_cs5530_mixer_read(unsigned long io, u8 reg) } static int snd_cs5530_create(struct snd_card *card, - struct pci_dev *pci, - struct snd_cs5530 **rchip) + struct pci_dev *pci) { - struct snd_cs5530 *chip; + struct snd_cs5530 *chip = card->private_data; unsigned long sb_base; u8 irq, dma8, dma16 = 0; u16 map; void __iomem *mem; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_cs5530_dev_free, - }; - *rchip = NULL; - - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } - chip->card = card; chip->pci = pci; - err = pci_request_regions(pci, "CS5530"); - if (err < 0) { - kfree(chip); - pci_disable_device(pci); + err = pcim_iomap_regions(pci, 1 << 0, "CS5530"); + if (err < 0) return err; - } chip->pci_base = pci_resource_start(pci, 0); - - mem = pci_ioremap_bar(pci, 0); - if (mem == NULL) { - snd_cs5530_free(chip); - return -EBUSY; - } - + mem = pcim_iomap_table(pci)[0]; map = readw(mem + 0x18); - iounmap(mem); /* Map bits 0:1 * 0x20 + 0x200 = sb base @@ -154,7 +113,6 @@ static int snd_cs5530_create(struct snd_card *card, dev_info(card->dev, "XpressAudio at 0x%lx\n", sb_base); else { dev_err(card->dev, "Could not find XpressAudio!\n"); - snd_cs5530_free(chip); return -ENODEV; } @@ -174,7 +132,6 @@ static int snd_cs5530_create(struct snd_card *card, dma16 = 7; else { dev_err(card->dev, "No 16bit DMA enabled\n"); - snd_cs5530_free(chip); return -ENODEV; } @@ -186,7 +143,6 @@ static int snd_cs5530_create(struct snd_card *card, dma8 = 3; else { dev_err(card->dev, "No 8bit DMA enabled\n"); - snd_cs5530_free(chip); return -ENODEV; } @@ -200,7 +156,6 @@ static int snd_cs5530_create(struct snd_card *card, irq = 10; else { dev_err(card->dev, "SoundBlaster IRQ not set\n"); - snd_cs5530_free(chip); return -ENODEV; } @@ -210,31 +165,21 @@ static int snd_cs5530_create(struct snd_card *card, dma16, SB_HW_CS5530, &chip->sb); if (err < 0) { dev_err(card->dev, "Could not create SoundBlaster\n"); - snd_cs5530_free(chip); return err; } err = snd_sb16dsp_pcm(chip->sb, 0); if (err < 0) { dev_err(card->dev, "Could not create PCM\n"); - snd_cs5530_free(chip); return err; } err = snd_sbmixer_new(chip->sb); if (err < 0) { dev_err(card->dev, "Could not create Mixer\n"); - snd_cs5530_free(chip); - return err; - } - - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_cs5530_free(chip); return err; } - *rchip = chip; return 0; } @@ -243,7 +188,7 @@ static int snd_cs5530_probe(struct pci_dev *pci, { static int dev; struct snd_card *card; - struct snd_cs5530 *chip = NULL; + struct snd_cs5530 *chip; int err; if (dev >= SNDRV_CARDS) @@ -253,27 +198,23 @@ static int snd_cs5530_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 = card->private_data; - err = snd_cs5530_create(card, pci, &chip); - if (err < 0) { - snd_card_free(card); + err = snd_cs5530_create(card, pci); + if (err < 0) return err; - } strcpy(card->driver, "CS5530"); strcpy(card->shortname, "CS5530 Audio"); sprintf(card->longname, "%s at 0x%lx", card->shortname, chip->pci_base); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; @@ -283,7 +224,6 @@ static struct pci_driver cs5530_driver = { .name = KBUILD_MODNAME, .id_table = snd_cs5530_ids, .probe = snd_cs5530_probe, - .remove = snd_cs5530_remove, }; module_pci_driver(cs5530_driver); From patchwork Tue Jul 13 14:28:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474729 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=-18.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, USER_AGENT_GIT 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 8D544C07E95 for ; Tue, 13 Jul 2021 14:37:04 +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 0DEC5610D1 for ; Tue, 13 Jul 2021 14:37:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DEC5610D1 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 9892A172A; Tue, 13 Jul 2021 16:36:12 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9892A172A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187022; bh=pBtt/uTISb8NPCkEom15usZ6QN8XM+za30pYh42Crn8=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=iWV0ZNlWcPsiB2KhkAIYI4YukeZfQrHPjVuJM4tqu3XN4QIFQTvgwvz5mukYSRoxN xiYvorCfEUA6LoMXOwtHnoQYKCBYngiAJU0mJz7tuOmbvpFosy0azW9e8oRgVsK/so JvyMlCAtIRzEobqnaJ4oE5ranhZinPE/+oYSFd7k= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8EA85F80515; Tue, 13 Jul 2021 16:30:05 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 31827F80534; Tue, 13 Jul 2021 16:29:37 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 D1BE6F80515 for ; Tue, 13 Jul 2021 16:29:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D1BE6F80515 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="FqXpN8gb"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="0/9zPKU7" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id A4B6D22855 for ; Tue, 13 Jul 2021 14:29:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186564; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H+FcHIP2zdusgbPrYoClAr9cEuLFcqZ/s7i7OKllpgQ=; b=FqXpN8gbgZa71FnKrp2fnWbWiLiiQJxJcdj8BlKdYdiPZMVPW78nHCW5mugtpB/t1Lj8np 32bN/KvUk3BElgNjIZ4iszZuJYxT1rMBNT7oDLBMNut2egIfBMEu2E/j9SxnSPda5QK9QN dJyVcTAbd1u3luemHpUkiZjnC9L738U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186564; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H+FcHIP2zdusgbPrYoClAr9cEuLFcqZ/s7i7OKllpgQ=; b=0/9zPKU7mHsdA7BDujlj0eRm2NF7nK2inW40ZMM2JtqsLbr5UPlRyiZCnVun8YrP/S1wWH jj1gSriGXlKew1Bw== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 93CF9A3B85; Tue, 13 Jul 2021 14:29:24 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 18/51] ALSA: fm801: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:24 +0200 Message-Id: <20210713142857.19654-19-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI fm801 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. Also the superfluous ac97 private_free callbacks were dropped, too. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/pci/fm801.c | 103 ++++++++-------------------------------------- 1 file changed, 17 insertions(+), 86 deletions(-) diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c index ed9dae87145b..9c22ff19e56d 100644 --- a/sound/pci/fm801.c +++ b/sound/pci/fm801.c @@ -1028,22 +1028,6 @@ FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",CAPTURE,SWITCH), FM801_I2S_MODE, FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), FM801_GEN_CTRL, 2, 1, 0), }; -static void snd_fm801_mixer_free_ac97_bus(struct snd_ac97_bus *bus) -{ - struct fm801 *chip = bus->private_data; - chip->ac97_bus = NULL; -} - -static void snd_fm801_mixer_free_ac97(struct snd_ac97 *ac97) -{ - struct fm801 *chip = ac97->private_data; - if (ac97->num == 0) { - chip->ac97 = NULL; - } else { - chip->ac97_sec = NULL; - } -} - static int snd_fm801_mixer(struct fm801 *chip) { struct snd_ac97_template ac97; @@ -1057,11 +1041,9 @@ static int snd_fm801_mixer(struct fm801 *chip) err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus); if (err < 0) return err; - chip->ac97_bus->private_free = snd_fm801_mixer_free_ac97_bus; memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; - ac97.private_free = snd_fm801_mixer_free_ac97; err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97); if (err < 0) return err; @@ -1177,55 +1159,35 @@ static void snd_fm801_chip_init(struct fm801 *chip) FM801_IRQ_PLAYBACK | FM801_IRQ_CAPTURE | FM801_IRQ_MPU); } -static int snd_fm801_free(struct fm801 *chip) +static void snd_fm801_free(struct snd_card *card) { + struct fm801 *chip = card->private_data; unsigned short cmdw; - if (chip->irq < 0) - goto __end_hw; - /* interrupt setup - mask everything */ cmdw = fm801_readw(chip, IRQ_MASK); cmdw |= 0x00c3; fm801_writew(chip, IRQ_MASK, cmdw); - devm_free_irq(chip->dev, chip->irq, chip); - - __end_hw: #ifdef CONFIG_SND_FM801_TEA575X_BOOL if (!(chip->tea575x_tuner & TUNER_DISABLED)) { snd_tea575x_exit(&chip->tea); v4l2_device_unregister(&chip->v4l2_dev); } #endif - return 0; -} - -static int snd_fm801_dev_free(struct snd_device *device) -{ - struct fm801 *chip = device->device_data; - return snd_fm801_free(chip); } static int snd_fm801_create(struct snd_card *card, struct pci_dev *pci, int tea575x_tuner, - int radio_nr, - struct fm801 **rchip) + int radio_nr) { - struct fm801 *chip; + struct fm801 *chip = card->private_data; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_fm801_dev_free, - }; - *rchip = NULL; err = pcim_enable_device(pci); if (err < 0) return err; - chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL); - if (chip == NULL) - return -ENOMEM; spin_lock_init(&chip->reg_lock); chip->card = card; chip->dev = &pci->dev; @@ -1253,7 +1215,6 @@ static int snd_fm801_create(struct snd_card *card, if (devm_request_irq(&pci->dev, pci->irq, snd_fm801_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_fm801_free(chip); return -EBUSY; } chip->irq = pci->irq; @@ -1261,20 +1222,13 @@ static int snd_fm801_create(struct snd_card *card, pci_set_master(pci); } + card->private_free = snd_fm801_free; snd_fm801_chip_init(chip); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_fm801_free(chip); - return err; - } - #ifdef CONFIG_SND_FM801_TEA575X_BOOL err = v4l2_device_register(&pci->dev, &chip->v4l2_dev); - if (err < 0) { - snd_fm801_free(chip); + if (err < 0) return err; - } chip->tea.v4l2_dev = &chip->v4l2_dev; chip->tea.radio_nr = radio_nr; chip->tea.private_data = chip; @@ -1284,7 +1238,6 @@ static int snd_fm801_create(struct snd_card *card, (chip->tea575x_tuner & TUNER_TYPE_MASK) < 4) { if (snd_tea575x_init(&chip->tea, THIS_MODULE)) { dev_err(card->dev, "TEA575x radio not found\n"); - snd_fm801_free(chip); return -ENODEV; } } else if ((chip->tea575x_tuner & TUNER_TYPE_MASK) == 0) { @@ -1312,8 +1265,6 @@ static int snd_fm801_create(struct snd_card *card, sizeof(chip->tea.card)); } #endif - - *rchip = chip; return 0; } @@ -1333,16 +1284,14 @@ static int snd_card_fm801_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; - err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip); - if (err < 0) { - snd_card_free(card); + chip = card->private_data; + err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev]); + if (err < 0) return err; - } - card->private_data = chip; strcpy(card->driver, "FM801"); strcpy(card->shortname, "ForteMedia FM801-"); @@ -1354,53 +1303,36 @@ static int snd_card_fm801_probe(struct pci_dev *pci, goto __fm801_tuner_only; err = snd_fm801_pcm(chip, 0); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_fm801_mixer(chip); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, chip->port + FM801_MPU401_DATA, MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, -1, &chip->rmidi); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0, chip->port + FM801_OPL3_BANK1, OPL3_HW_OPL3_FM801, 1, &opl3); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } __fm801_tuner_only: err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_card_fm801_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - #ifdef CONFIG_PM_SLEEP static const unsigned char saved_regs[] = { FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC, @@ -1468,7 +1400,6 @@ static struct pci_driver fm801_driver = { .name = KBUILD_MODNAME, .id_table = snd_fm801_ids, .probe = snd_card_fm801_probe, - .remove = snd_card_fm801_remove, .driver = { .pm = SND_FM801_PM_OPS, }, From patchwork Tue Jul 13 14:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474728 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=-18.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, USER_AGENT_GIT 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 CA60FC11F66 for ; Tue, 13 Jul 2021 14:37:31 +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 58992610CB for ; Tue, 13 Jul 2021 14:37:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 58992610CB 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 E3CBE1714; Tue, 13 Jul 2021 16:36:39 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E3CBE1714 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187050; bh=tbIThGY2VsWnck0Zq9qRfZnheBoMGQGe3YYNJ1zqUQA=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lhEbx5nOs/s6efWW3PcENH4fazz8D5hsEgQmfCJyN/7oZ8ZxjSRxIFd5U0hXoQ2TU V7pnzD7jlfJ2EmdT524+CxVi/M1pWINhjaysxUl4iZevmtsv+n3BQ+wMI99JSMryME XGgf30rjhdBYTLggo2f9IskJ0ZW7OkgMAk6mnBTA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8614DF80537; Tue, 13 Jul 2021 16:30:13 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B0953F80538; Tue, 13 Jul 2021 16:29:40 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 8F3EBF8051C for ; Tue, 13 Jul 2021 16:29:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8F3EBF8051C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="qx1LxNPK"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="r3cRolaA" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6CBF122837 for ; Tue, 13 Jul 2021 14:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186566; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2UJlcNtLCmRyyiZVZtAne3g+hTdewxTFXlBLrEUT66E=; b=qx1LxNPKrLMjKDzn7GDxanOEw4EINMUZ76jJr9erjENK02lh/ItdxdbWMUkrpoR1dqvxip qay/VS4p1U4V1nz4wlt38ml4zBSuvhiXDgkA+iYlnCYiNzXfGRBH5oWD7sI+5HJbC9rZtJ 9ciygL1Z819ntEJ6OulqGeGcKvA/GXc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186566; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2UJlcNtLCmRyyiZVZtAne3g+hTdewxTFXlBLrEUT66E=; b=r3cRolaA6DEOL//ZjWhDVcRNRRamCuScTsjLLXbFON9QSEgPEGqq2xKdiNCEx2alg0dU6b 6nWuBs96hKWmIdDQ== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 6742CA3B90; Tue, 13 Jul 2021 14:29:26 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 20/51] ALSA: rme32: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:26 +0200 Message-Id: <20210713142857.19654-21-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI rme32 driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/pci/rme32.c | 49 +++++++++++------------------------------------ 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c index b5b357853c94..5b6bd9f0b2f7 100644 --- a/sound/pci/rme32.c +++ b/sound/pci/rme32.c @@ -1278,27 +1278,10 @@ static const struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = { .ack = snd_rme32_capture_fd_ack, }; -static void snd_rme32_free(void *private_data) +static void snd_rme32_free(struct rme32 *rme32) { - struct rme32 *rme32 = (struct rme32 *) private_data; - - if (rme32 == NULL) { - return; - } - if (rme32->irq >= 0) { + if (rme32->irq >= 0) snd_rme32_pcm_stop(rme32, 0); - free_irq(rme32->irq, (void *) rme32); - rme32->irq = -1; - } - if (rme32->iobase) { - iounmap(rme32->iobase); - rme32->iobase = NULL; - } - if (rme32->port) { - pci_release_regions(rme32->pci); - rme32->port = 0; - } - pci_disable_device(rme32->pci); } static void snd_rme32_free_spdif_pcm(struct snd_pcm *pcm) @@ -1322,7 +1305,7 @@ static int snd_rme32_create(struct rme32 *rme32) rme32->irq = -1; spin_lock_init(&rme32->lock); - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; @@ -1331,16 +1314,16 @@ static int snd_rme32_create(struct rme32 *rme32) return err; rme32->port = pci_resource_start(rme32->pci, 0); - rme32->iobase = ioremap(rme32->port, RME32_IO_SIZE); + rme32->iobase = devm_ioremap(&pci->dev, rme32->port, RME32_IO_SIZE); if (!rme32->iobase) { dev_err(rme32->card->dev, "unable to remap memory region 0x%lx-0x%lx\n", - rme32->port, rme32->port + RME32_IO_SIZE - 1); + rme32->port, rme32->port + RME32_IO_SIZE - 1); return -ENOMEM; } - if (request_irq(pci->irq, snd_rme32_interrupt, IRQF_SHARED, - KBUILD_MODNAME, rme32)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_rme32_interrupt, + IRQF_SHARED, KBUILD_MODNAME, rme32)) { dev_err(rme32->card->dev, "unable to grab IRQ %d\n", pci->irq); return -EBUSY; } @@ -1907,8 +1890,8 @@ snd_rme32_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) return -ENOENT; } - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, - sizeof(struct rme32), &card); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, + sizeof(*rme32), &card); if (err < 0) return err; card->private_free = snd_rme32_card_free; @@ -1918,10 +1901,8 @@ snd_rme32_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) if (fullduplex[dev]) rme32->fullduplex_mode = 1; err = snd_rme32_create(rme32); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } strcpy(card->driver, "Digi32"); switch (rme32->pci->device) { @@ -1939,25 +1920,17 @@ snd_rme32_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) card->shortname, rme32->rev, rme32->port, rme32->irq); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_rme32_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver rme32_driver = { .name = KBUILD_MODNAME, .id_table = snd_rme32_ids, .probe = snd_rme32_probe, - .remove = snd_rme32_remove, }; module_pci_driver(rme32_driver); From patchwork Tue Jul 13 14:28:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474727 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=-18.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, USER_AGENT_GIT 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 9CAA7C07E95 for ; Tue, 13 Jul 2021 14:38:13 +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 1F14C610CB for ; Tue, 13 Jul 2021 14:38:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F14C610CB 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 AF28916DF; Tue, 13 Jul 2021 16:37:21 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AF28916DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187091; bh=+zZ82PvAwfuGDL+lk+bxHefvcy6qWb9WRLvqm6rUJtQ=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YVV5kUHzr/GRtM2b5jN9JSrIZmo/5UURHH3F0Akw2NUbMxnM3qqpMvXemOmlp2Ot5 81f06Xn8XE9U4UK/RLB0K2HGvW+fd4pL1kOvJN+C7CFTqIlNgamr+X0rct0O/9vMuT DbuAXjEdNEeMnxdvYGQs7pJgt364xtCP6rxqI8f0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1B1C5F80551; Tue, 13 Jul 2021 16:30:16 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 68B02F80558; Tue, 13 Jul 2021 16:29:44 +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 72B00F804B3 for ; Tue, 13 Jul 2021 16:29:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 72B00F804B3 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="xlohLgop"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Mj5tU57n" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4A558201E4 for ; Tue, 13 Jul 2021 14:29:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186567; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UPwkniyc4i2ebrNRn1DxMXVIXeRB3qPV1y4v5jAw8Dk=; b=xlohLgopJOcv9j4bEkJzvA3iRV504PRxq6d17qJxlM94TErNmaR/6hFXGFWW3ua6btIl50 VpdV+6KpjZXphJ9eVpB8XNwM+hVjll7uolA0WAgzA0vsPduLHpFPKN3WQdDcL90ZE1F2Ep xvqV+0/TlsT8woEBQ7Si06Zj2Epa8aI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186567; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UPwkniyc4i2ebrNRn1DxMXVIXeRB3qPV1y4v5jAw8Dk=; b=Mj5tU57nLij5hqMwZ077VvbKTb0dgdxUiyt5YVm8bblIo85Nx7KWUBzONebza2twGZrr1K abUs0i318GXumiDQ== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 3A2F6A3B90; Tue, 13 Jul 2021 14:29:27 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 21/51] ALSA: rme96: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:27 +0200 Message-Id: <20210713142857.19654-22-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI rme96 driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/pci/rme96.c | 57 ++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 43 deletions(-) diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c index fc7ac077559c..8fc811504920 100644 --- a/sound/pci/rme96.c +++ b/sound/pci/rme96.c @@ -1562,33 +1562,17 @@ static const struct snd_pcm_ops snd_rme96_capture_adat_ops = { }; static void -snd_rme96_free(void *private_data) +snd_rme96_free(struct rme96 *rme96) { - struct rme96 *rme96 = (struct rme96 *)private_data; - - if (!rme96) - return; - if (rme96->irq >= 0) { snd_rme96_trigger(rme96, RME96_STOP_BOTH); rme96->areg &= ~RME96_AR_DAC_EN; writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG); - free_irq(rme96->irq, (void *)rme96); - rme96->irq = -1; - } - if (rme96->iobase) { - iounmap(rme96->iobase); - rme96->iobase = NULL; - } - if (rme96->port) { - pci_release_regions(rme96->pci); - rme96->port = 0; } #ifdef CONFIG_PM_SLEEP vfree(rme96->playback_suspend_buffer); vfree(rme96->capture_suspend_buffer); #endif - pci_disable_device(rme96->pci); } static void @@ -1614,7 +1598,7 @@ snd_rme96_create(struct rme96 *rme96) rme96->irq = -1; spin_lock_init(&rme96->lock); - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; @@ -1623,16 +1607,16 @@ snd_rme96_create(struct rme96 *rme96) return err; rme96->port = pci_resource_start(rme96->pci, 0); - rme96->iobase = ioremap(rme96->port, RME96_IO_SIZE); + rme96->iobase = devm_ioremap(&pci->dev, rme96->port, RME96_IO_SIZE); if (!rme96->iobase) { dev_err(rme96->card->dev, "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); - return -ENOMEM; + return -EBUSY; } - if (request_irq(pci->irq, snd_rme96_interrupt, IRQF_SHARED, - KBUILD_MODNAME, rme96)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_rme96_interrupt, + IRQF_SHARED, KBUILD_MODNAME, rme96)) { dev_err(rme96->card->dev, "unable to grab IRQ %d\n", pci->irq); return -EBUSY; } @@ -2462,8 +2446,8 @@ snd_rme96_probe(struct pci_dev *pci, dev++; return -ENOENT; } - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, - sizeof(struct rme96), &card); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, + sizeof(*rme96), &card); if (err < 0) return err; card->private_free = snd_rme96_card_free; @@ -2472,19 +2456,15 @@ snd_rme96_probe(struct pci_dev *pci, rme96->pci = pci; err = snd_rme96_create(rme96); if (err) - goto free_card; + return err; #ifdef CONFIG_PM_SLEEP rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); - if (!rme96->playback_suspend_buffer) { - err = -ENOMEM; - goto free_card; - } + if (!rme96->playback_suspend_buffer) + return -ENOMEM; rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); - if (!rme96->capture_suspend_buffer) { - err = -ENOMEM; - goto free_card; - } + if (!rme96->capture_suspend_buffer) + return -ENOMEM; #endif strcpy(card->driver, "Digi96"); @@ -2511,26 +2491,17 @@ snd_rme96_probe(struct pci_dev *pci, rme96->port, rme96->irq); err = snd_card_register(card); if (err) - goto free_card; + return err; pci_set_drvdata(pci, card); dev++; return 0; -free_card: - snd_card_free(card); - return err; -} - -static void snd_rme96_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); } static struct pci_driver rme96_driver = { .name = KBUILD_MODNAME, .id_table = snd_rme96_ids, .probe = snd_rme96_probe, - .remove = snd_rme96_remove, .driver = { .pm = RME96_PM_OPS, }, From patchwork Tue Jul 13 14:28:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474726 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=-18.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, USER_AGENT_GIT 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 31FF7C07E95 for ; Tue, 13 Jul 2021 14:38:54 +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 AF397610D1 for ; Tue, 13 Jul 2021 14:38:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF397610D1 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 4CD051727; Tue, 13 Jul 2021 16:38:02 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4CD051727 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187132; bh=bNSQemfVC1DiX6Uq9y18hFJZpLstF4eX4rh3LBHuYdw=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=QHHVrN0isdg98kq24l5J7lyj+DZyNyDzsXEeDUJmYwyRsODZmzoyHsxACFlPbB0Wk pl2MoLUId71Ed/0VQZYwLbpasGZoGzSPBLPsnXX46HOyd+8FiXeK/ufJmTdZCOnzDo oO+kPfHQHlqHAcu1Ii4Lsx2x+VOtdt5KmrDkC0qo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 2B983F804FD; Tue, 13 Jul 2021 16:30:24 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 94939F80563; Tue, 13 Jul 2021 16:29:46 +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 17190F8051F for ; Tue, 13 Jul 2021 16:29:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 17190F8051F Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="WAqOZk2C"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="XJdETGTv" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id CC1BE201E4 for ; Tue, 13 Jul 2021 14:29:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186568; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7FdamqqrTOHT6NYW+ddkP/Za1baGYW44k+vEw1Su2q4=; b=WAqOZk2COrXkN54u1MNGOGNfyvzQOhYIR4fXwiSY3b386lmBRdFaYGy+AEzAJICy9jReGx h5lrLqgop3v/t6ZtetYctGm1r+Iyhes1HlcpHPIVFuBb5Zkv9xfV2lSuWyfr/lDPt2rT0T Vpe7/4Hg10UWklha/gM80CM/aZx8adQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186568; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7FdamqqrTOHT6NYW+ddkP/Za1baGYW44k+vEw1Su2q4=; b=XJdETGTv8BbWaKa5WieI2nsB3J5GY1yrKn6AFJYA2cxrk/4uYDhoKhLm59UyBHl6CU4rxP mmllMq+o9gA39XAg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id C4FD6A3B83; Tue, 13 Jul 2021 14:29:28 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 23/51] ALSA: sonicvibes: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:29 +0200 Message-Id: <20210713142857.19654-24-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI sonicvibes 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/sonicvibes.c | 117 ++++++++++------------------------------- 1 file changed, 27 insertions(+), 90 deletions(-) diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c index 03a48da897e3..c8c49881008f 100644 --- a/sound/pci/sonicvibes.c +++ b/sound/pci/sonicvibes.c @@ -1193,69 +1193,43 @@ static inline int snd_sonicvibes_create_gameport(struct sonicvibes *sonic) { ret static inline void snd_sonicvibes_free_gameport(struct sonicvibes *sonic) { } #endif -static int snd_sonicvibes_free(struct sonicvibes *sonic) +static void snd_sonicvibes_free(struct snd_card *card) { + struct sonicvibes *sonic = card->private_data; + snd_sonicvibes_free_gameport(sonic); pci_write_config_dword(sonic->pci, 0x40, sonic->dmaa_port); pci_write_config_dword(sonic->pci, 0x48, sonic->dmac_port); - if (sonic->irq >= 0) - free_irq(sonic->irq, sonic); - release_and_free_resource(sonic->res_dmaa); - release_and_free_resource(sonic->res_dmac); - pci_release_regions(sonic->pci); - pci_disable_device(sonic->pci); - kfree(sonic); - return 0; -} - -static int snd_sonicvibes_dev_free(struct snd_device *device) -{ - struct sonicvibes *sonic = device->device_data; - return snd_sonicvibes_free(sonic); } static int snd_sonicvibes_create(struct snd_card *card, struct pci_dev *pci, int reverb, - int mge, - struct sonicvibes **rsonic) + int mge) { - struct sonicvibes *sonic; + struct sonicvibes *sonic = card->private_data; unsigned int dmaa, dmac; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_sonicvibes_dev_free, - }; - *rsonic = NULL; /* enable PCI device */ - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; /* check, if we can restrict PCI DMA transfers to 24 bits */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) { dev_err(card->dev, "architecture does not support 24bit PCI busmaster DMA\n"); - pci_disable_device(pci); return -ENXIO; } - sonic = kzalloc(sizeof(*sonic), GFP_KERNEL); - if (sonic == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } spin_lock_init(&sonic->reg_lock); sonic->card = card; sonic->pci = pci; sonic->irq = -1; err = pci_request_regions(pci, "S3 SonicVibes"); - if (err < 0) { - kfree(sonic); - pci_disable_device(pci); + if (err < 0) return err; - } sonic->sb_port = pci_resource_start(pci, 0); sonic->enh_port = pci_resource_start(pci, 1); @@ -1263,14 +1237,14 @@ static int snd_sonicvibes_create(struct snd_card *card, sonic->midi_port = pci_resource_start(pci, 3); sonic->game_port = pci_resource_start(pci, 4); - if (request_irq(pci->irq, snd_sonicvibes_interrupt, IRQF_SHARED, - KBUILD_MODNAME, sonic)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_sonicvibes_interrupt, + IRQF_SHARED, KBUILD_MODNAME, sonic)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_sonicvibes_free(sonic); return -EBUSY; } sonic->irq = pci->irq; card->sync_irq = sonic->irq; + card->private_free = snd_sonicvibes_free; pci_read_config_dword(pci, 0x40, &dmaa); pci_read_config_dword(pci, 0x48, &dmac); @@ -1294,17 +1268,17 @@ static int snd_sonicvibes_create(struct snd_card *card, pci_write_config_dword(pci, 0x40, dmaa); pci_write_config_dword(pci, 0x48, dmac); - sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A"); + sonic->res_dmaa = devm_request_region(&pci->dev, dmaa, 0x10, + "S3 SonicVibes DDMA-A"); if (!sonic->res_dmaa) { - snd_sonicvibes_free(sonic); dev_err(card->dev, "unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1); return -EBUSY; } - sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C"); + sonic->res_dmac = devm_request_region(&pci->dev, dmac, 0x10, + "S3 SonicVibes DDMA-C"); if (!sonic->res_dmac) { - snd_sonicvibes_free(sonic); dev_err(card->dev, "unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1); @@ -1365,15 +1339,7 @@ static int snd_sonicvibes_create(struct snd_card *card, #endif sonic->revision = snd_sonicvibes_in(sonic, SV_IREG_REVISION); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, sonic, &ops); - if (err < 0) { - snd_sonicvibes_free(sonic); - return err; - } - snd_sonicvibes_proc_init(sonic); - - *rsonic = sonic; return 0; } @@ -1429,7 +1395,7 @@ static int snd_sonic_probe(struct pci_dev *pci, struct sonicvibes *sonic; struct snd_rawmidi *midi_uart; struct snd_opl3 *opl3; - int idx, err; + int err; if (dev >= SNDRV_CARDS) return -ENODEV; @@ -1438,25 +1404,16 @@ static int snd_sonic_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(*sonic), &card); if (err < 0) return err; - for (idx = 0; idx < 5; idx++) { - if (pci_resource_start(pci, idx) == 0 || - !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) { - snd_card_free(card); - return -ENODEV; - } - } + sonic = card->private_data; err = snd_sonicvibes_create(card, pci, reverb[dev] ? 1 : 0, - mge[dev] ? 1 : 0, - &sonic); - if (err < 0) { - snd_card_free(card); + mge[dev] ? 1 : 0); + if (err < 0) return err; - } strcpy(card->driver, "SonicVibes"); strcpy(card->shortname, "S3 SonicVibes"); @@ -1467,65 +1424,45 @@ static int snd_sonic_probe(struct pci_dev *pci, sonic->irq); err = snd_sonicvibes_pcm(sonic, 0); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_sonicvibes_mixer(sonic); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_mpu401_uart_new(card, 0, MPU401_HW_SONICVIBES, sonic->midi_port, MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, -1, &midi_uart); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } snd_sonicvibes_midi(sonic, midi_uart); err = snd_opl3_create(card, sonic->synth_port, sonic->synth_port + 2, OPL3_HW_OPL3_SV, 1, &opl3); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_sonicvibes_create_gameport(sonic); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_sonic_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver sonicvibes_driver = { .name = KBUILD_MODNAME, .id_table = snd_sonic_ids, .probe = snd_sonic_probe, - .remove = snd_sonic_remove, }; module_pci_driver(sonicvibes_driver); From patchwork Tue Jul 13 14:28:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474724 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=-18.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, USER_AGENT_GIT 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 71B16C07E95 for ; Tue, 13 Jul 2021 14:40:17 +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 EB46D610CB for ; Tue, 13 Jul 2021 14:40:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB46D610CB 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 9272B1724; Tue, 13 Jul 2021 16:39:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9272B1724 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187215; bh=NcrN6L4WZTUj1jg6eN92u1KO9xlQjaJzRLodgbjRVqY=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=oFJQIk4ePcwAEqCtUjnGJpwDvkdLH45qPhP7pVQ3B1QyewTkNc8OSxmX78g/mss7i JJlnju9si9Jh5i9Eo3wU6l6kvXgy2vkNmmLwa5gT+DWU6NEY3ibC0g0+KrCoykWyWh yWEJks+d5uHQjDe8Xb3wrNm/S/eRc+UGv4zyjif0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 992EBF805B3; Tue, 13 Jul 2021 16:30:26 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id CE9BFF80571; Tue, 13 Jul 2021 16:29:49 +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 7731FF8050F for ; Tue, 13 Jul 2021 16:29:30 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7731FF8050F Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="nj6pr70Z"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="WTtUaSKT" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4DF28201E4 for ; Tue, 13 Jul 2021 14:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8nus57fjny4yCUjw8vUksNK+8q7u3TAt5nxvdIRA/wE=; b=nj6pr70ZO13vpTwTOmcKTxp4M6Nhhp1alfzoQy35bNxsFiZW8WUg/ot5iEoawGKSWJyKwK fzO++03oavut+PqMciXAckU+YXI8GehzCI61MC3GQSQ4mTAMYO8lxu5Y8DlLbPiltah5jI Y4DzFs4n7rhNSSAIE8jpllxmX3x0960= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8nus57fjny4yCUjw8vUksNK+8q7u3TAt5nxvdIRA/wE=; b=WTtUaSKTghhFVrlrSozG9R4uZz4yH2iEh+WW4EKHOWNOf+wIS0BFftX/r/LmiIH4VARQY5 hpW78pPAnc+iC9AA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 3C532A3B83; Tue, 13 Jul 2021 14:29:30 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 25/51] ALSA: ali5451: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:31 +0200 Message-Id: <20210713142857.19654-26-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI ali5451 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/ali5451/ali5451.c | 88 +++++++++---------------------------- 1 file changed, 20 insertions(+), 68 deletions(-) diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c index 0d66b92466d5..ccbf9e2c72d6 100644 --- a/sound/pci/ali5451/ali5451.c +++ b/sound/pci/ali5451/ali5451.c @@ -1914,22 +1914,14 @@ static SIMPLE_DEV_PM_OPS(ali_pm, ali_suspend, ali_resume); #define ALI_PM_OPS NULL #endif /* CONFIG_PM_SLEEP */ -static int snd_ali_free(struct snd_ali * codec) +static void snd_ali_free(struct snd_card *card) { + struct snd_ali *codec = card->private_data; + if (codec->hw_initialized) snd_ali_disable_address_interrupt(codec); - if (codec->irq >= 0) - free_irq(codec->irq, codec); - if (codec->port) - pci_release_regions(codec->pci); - pci_disable_device(codec->pci); -#ifdef CONFIG_PM_SLEEP - kfree(codec->image); -#endif pci_dev_put(codec->pci_m1533); pci_dev_put(codec->pci_m7101); - kfree(codec); - return 0; } static int snd_ali_chip_init(struct snd_ali *codec) @@ -2017,8 +2009,9 @@ static int snd_ali_resources(struct snd_ali *codec) return err; codec->port = pci_resource_start(codec->pci, 0); - if (request_irq(codec->pci->irq, snd_ali_card_interrupt, - IRQF_SHARED, KBUILD_MODNAME, codec)) { + if (devm_request_irq(&codec->pci->dev, codec->pci->irq, + snd_ali_card_interrupt, + IRQF_SHARED, KBUILD_MODNAME, codec)) { dev_err(codec->card->dev, "Unable to request irq.\n"); return -EBUSY; } @@ -2027,48 +2020,29 @@ static int snd_ali_resources(struct snd_ali *codec) dev_dbg(codec->card->dev, "resources allocated.\n"); return 0; } -static int snd_ali_dev_free(struct snd_device *device) -{ - struct snd_ali *codec = device->device_data; - snd_ali_free(codec); - return 0; -} static int snd_ali_create(struct snd_card *card, struct pci_dev *pci, int pcm_streams, - int spdif_support, - struct snd_ali **r_ali) + int spdif_support) { struct snd_ali *codec; int i, err; unsigned short cmdw; - static const struct snd_device_ops ops = { - .dev_free = snd_ali_dev_free, - }; - - *r_ali = NULL; dev_dbg(card->dev, "creating ...\n"); /* enable PCI device */ - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; /* check, if we can restrict PCI DMA transfers to 31 bits */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31))) { dev_err(card->dev, "architecture does not support 31bit PCI busmaster DMA\n"); - pci_disable_device(pci); return -ENXIO; } - codec = kzalloc(sizeof(*codec), GFP_KERNEL); - if (!codec) { - pci_disable_device(pci); - return -ENOMEM; - } - spin_lock_init(&codec->reg_lock); spin_lock_init(&codec->voice_alloc); @@ -2089,12 +2063,10 @@ static int snd_ali_create(struct snd_card *card, cmdw |= PCI_COMMAND_IO; pci_write_config_word(pci, PCI_COMMAND, cmdw); } - pci_set_master(pci); - if (snd_ali_resources(codec)) { - snd_ali_free(codec); + if (snd_ali_resources(codec)) return -EBUSY; - } + card->private_free = snd_ali_free; codec->synth.chmap = 0; codec->synth.chcnt = 0; @@ -2121,24 +2093,15 @@ static int snd_ali_create(struct snd_card *card, codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); if (!codec->pci_m1533) { dev_err(card->dev, "cannot find ALi 1533 chip.\n"); - snd_ali_free(codec); return -ENODEV; } /* M7101: power management */ codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) { dev_err(card->dev, "cannot find ALi 7101 chip.\n"); - snd_ali_free(codec); return -ENODEV; } - dev_dbg(card->dev, "snd_device_new is called.\n"); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops); - if (err < 0) { - snd_ali_free(codec); - return err; - } - /* initialise synth voices*/ for (i = 0; i < ALI_CHANNELS; i++) codec->synth.voices[i].number = i; @@ -2150,16 +2113,14 @@ static int snd_ali_create(struct snd_card *card, } #ifdef CONFIG_PM_SLEEP - codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL); + codec->image = devm_kmalloc(&pci->dev, sizeof(*codec->image), + GFP_KERNEL); if (!codec->image) dev_warn(card->dev, "can't allocate apm buffer\n"); #endif snd_ali_enable_address_interrupt(codec); codec->hw_initialized = 1; - - *r_ali = codec; - dev_dbg(card->dev, "created.\n"); return 0; } @@ -2172,24 +2133,25 @@ static int snd_ali_probe(struct pci_dev *pci, dev_dbg(&pci->dev, "probe ...\n"); - err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, + sizeof(*codec), &card); if (err < 0) return err; + codec = card->private_data; - err = snd_ali_create(card, pci, pcm_channels, spdif, &codec); + err = snd_ali_create(card, pci, pcm_channels, spdif); if (err < 0) - goto error; - card->private_data = codec; + return err; dev_dbg(&pci->dev, "mixer building ...\n"); err = snd_ali_mixer(codec); if (err < 0) - goto error; + return err; dev_dbg(&pci->dev, "pcm building ...\n"); err = snd_ali_build_pcms(codec); if (err < 0) - goto error; + return err; snd_ali_proc_init(codec); @@ -2202,26 +2164,16 @@ static int snd_ali_probe(struct pci_dev *pci, dev_dbg(&pci->dev, "register card.\n"); err = snd_card_register(card); if (err < 0) - goto error; + return err; pci_set_drvdata(pci, card); return 0; - - error: - snd_card_free(card); - return err; -} - -static void snd_ali_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); } static struct pci_driver ali5451_driver = { .name = KBUILD_MODNAME, .id_table = snd_ali_ids, .probe = snd_ali_probe, - .remove = snd_ali_remove, .driver = { .pm = ALI_PM_OPS, }, From patchwork Tue Jul 13 14:28:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474725 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=-18.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, USER_AGENT_GIT 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 762DDC07E95 for ; Tue, 13 Jul 2021 14:39:38 +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 E3F116115B for ; Tue, 13 Jul 2021 14:39:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3F116115B 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 814FF171C; Tue, 13 Jul 2021 16:38:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 814FF171C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187176; bh=kkFw+cG+OvXBXoonKwLOysgYvtzZDiCs0oiGkjoNbXQ=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IlymXCEUZHO87MgCwwiFMbf4ePDlV9iBu7TWqmYsEFq5dAAVwSORaiblgq/wzxBrs izs3ghU+RofIvQm0mNiWqJztlOtkoTb/n5az+RtFiRemFhieg06NsZT59vHsg4Otay 2yVDPJ+42bz5vgARfZsVtphHr5CtdrCU1KXSMFE0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8FCB4F805AB; Tue, 13 Jul 2021 16:30:25 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D5427F80570; Tue, 13 Jul 2021 16:29:48 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 42076F80524 for ; Tue, 13 Jul 2021 16:29:31 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 42076F80524 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Cv9bso6I"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="6TzU4L/w" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id E9AA822837 for ; Tue, 13 Jul 2021 14:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3mr/zNFJMS6D20lvwn61DOLlz7DX+1O7pzWKGYewfM8=; b=Cv9bso6IDYK8NDovdnUDXTRaYI5qhtv/9UCwxsCqHlRwoTJueal8LmCp84JLBLimoeZ7BJ wc3KYA6W3Sc1kasbVUMkX4fQ5JcNvAbacxLYEUkyQZF1xD9HCuIFl8XlpxxXgoi40DSOzg cqydxPjHvc2sKCmlSX3CD1f3KYFh5Gs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3mr/zNFJMS6D20lvwn61DOLlz7DX+1O7pzWKGYewfM8=; b=6TzU4L/w2l1XDmd6DSgywtoY6fnfF079RCV3+1ev/iKzpGaMnLrhjXjBqQEgQ3Ayvka+ub UM8/i3dVCWN5aMBg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id D8496A3B8A; Tue, 13 Jul 2021 14:29:30 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 26/51] ALSA: au88x0: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:32 +0200 Message-Id: <20210713142857.19654-27-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI au88x0 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/au88x0/au88x0.c | 134 +++++++++----------------------------- 1 file changed, 29 insertions(+), 105 deletions(-) diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c index 1f7fee470266..342ef2a6655e 100644 --- a/sound/pci/au88x0/au88x0.c +++ b/sound/pci/au88x0/au88x0.c @@ -123,56 +123,35 @@ static void snd_vortex_workaround(struct pci_dev *vortex, int fix) // component-destructor // (see "Management of Cards and Components") -static int snd_vortex_dev_free(struct snd_device *device) +static void snd_vortex_free(struct snd_card *card) { - vortex_t *vortex = device->device_data; + vortex_t *vortex = card->private_data; vortex_gameport_unregister(vortex); vortex_core_shutdown(vortex); - // Take down PCI interface. - free_irq(vortex->irq, vortex); - iounmap(vortex->mmio); - pci_release_regions(vortex->pci_dev); - pci_disable_device(vortex->pci_dev); - kfree(vortex); - - return 0; } // chip-specific constructor // (see "Management of Cards and Components") static int -snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip) +snd_vortex_create(struct snd_card *card, struct pci_dev *pci) { - vortex_t *chip; + vortex_t *chip = card->private_data; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_vortex_dev_free, - }; - - *rchip = NULL; // check PCI availability (DMA). - 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(32))) { dev_err(card->dev, "error to set DMA mask\n"); - pci_disable_device(pci); return -ENXIO; } - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } - chip->card = card; // initialize the stuff chip->pci_dev = pci; - chip->io = pci_resource_start(pci, 0); chip->vendor = pci->vendor; chip->device = pci->device; chip->card = card; @@ -181,16 +160,12 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip) // (1) PCI resource allocation // Get MMIO area // - err = pci_request_regions(pci, CARD_NAME_SHORT); + err = pcim_iomap_regions(pci, 1 << 0, CARD_NAME_SHORT); if (err) - goto regions_out; + return err; - chip->mmio = pci_ioremap_bar(pci, 0); - if (!chip->mmio) { - dev_err(card->dev, "MMIO area remap failed.\n"); - err = -ENOMEM; - goto ioremap_out; - } + chip->io = pci_resource_start(pci, 0); + chip->mmio = pcim_iomap_table(pci)[0]; /* Init audio core. * This must be done before we do request_irq otherwise we can get spurious @@ -198,44 +173,22 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip) err = vortex_core_init(chip); if (err) { dev_err(card->dev, "hw core init failed\n"); - goto core_out; + return err; } - err = request_irq(pci->irq, vortex_interrupt, - IRQF_SHARED, KBUILD_MODNAME, chip); + err = devm_request_irq(&pci->dev, pci->irq, vortex_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip); if (err) { dev_err(card->dev, "cannot grab irq\n"); - goto irq_out; + return err; } chip->irq = pci->irq; card->sync_irq = chip->irq; + card->private_free = snd_vortex_free; pci_set_master(pci); // End of PCI setup. - - // Register alsa root device. - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) - goto alloc_out; - - *rchip = chip; - return 0; - - alloc_out: - free_irq(chip->irq, chip); - irq_out: - vortex_core_shutdown(chip); - core_out: - iounmap(chip->mmio); - ioremap_out: - pci_release_regions(chip->pci_dev); - regions_out: - pci_disable_device(chip->pci_dev); - //FIXME: this not the right place to unregister the gameport - vortex_gameport_unregister(chip); - kfree(chip); - return err; } // constructor -- see "Constructor" sub-section @@ -255,17 +208,16 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) return -ENOENT; } // (2) - 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 = card->private_data; // (3) - err = snd_vortex_create(card, pci, &chip); - if (err < 0) { - snd_card_free(card); + err = snd_vortex_create(card, pci); + if (err < 0) return err; - } snd_vortex_workaround(pci, pcifix[dev]); // Card details needed in snd_vortex_midi @@ -276,50 +228,37 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) // (4) Alloc components. err = snd_vortex_mixer(chip); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } // ADB pcm. err = snd_vortex_new_pcm(chip, VORTEX_PCM_ADB, NR_PCM); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } #ifndef CHIP_AU8820 // ADB SPDIF err = snd_vortex_new_pcm(chip, VORTEX_PCM_SPDIF, 1); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } // A3D err = snd_vortex_new_pcm(chip, VORTEX_PCM_A3D, NR_A3D); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } #endif /* // ADB I2S if ((err = snd_vortex_new_pcm(chip, VORTEX_PCM_I2S, 1)) < 0) { - snd_card_free(card); return err; } */ #ifndef CHIP_AU8810 // WT pcm. err = snd_vortex_new_pcm(chip, VORTEX_PCM_WT, NR_WT); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } #endif err = snd_vortex_midi(chip); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } vortex_gameport_register(chip); @@ -342,15 +281,11 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) // (5) err = pci_read_config_word(pci, PCI_DEVICE_ID, &chip->device); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = pci_read_config_word(pci, PCI_VENDOR_ID, &chip->vendor); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } chip->rev = pci->revision; #ifdef CHIP_AU8830 if ((chip->rev) != 0xfe && (chip->rev) != 0xfa) { @@ -359,18 +294,14 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) chip->rev); dev_alert(card->dev, "Please email the results of 'lspci -vv' to openvortex-dev@nongnu.org.\n"); - snd_card_free(card); - err = -ENODEV; - return err; + return -ENODEV; } #endif // (6) err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } // (7) pci_set_drvdata(pci, card); dev++; @@ -379,18 +310,11 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) return 0; } -// destructor -- see "Destructor" sub-section -static void snd_vortex_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - // pci_driver definition static struct pci_driver vortex_driver = { .name = KBUILD_MODNAME, .id_table = snd_vortex_ids, .probe = snd_vortex_probe, - .remove = snd_vortex_remove, }; module_pci_driver(vortex_driver); From patchwork Tue Jul 13 14:28:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474723 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=-18.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, USER_AGENT_GIT 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 6050AC07E95 for ; Tue, 13 Jul 2021 14:41:01 +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 BB5376127C for ; Tue, 13 Jul 2021 14:41:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB5376127C 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 C81CD172A; Tue, 13 Jul 2021 16:40:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C81CD172A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187258; bh=M61xlYjISGekzwcgH9tpsxHic38nO0IrBeBX+A4jb64=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=r3cSv1JhV4VPeI6RvEbjXWwKFmAJaE7Sz6QCqOYl0Z7CsaACPMXAOCaPyFpslHo6K hHxvt2fBAeeQavMgaN6w0iJbRB5JR2E03u80zOLV8YzkSYeepJR7LSMxj+bkMcKaiL 3DUl6kfIk6+txWD27C3CcnZV7oesSVd6quB5B4mE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id EEF42F805C2; Tue, 13 Jul 2021 16:30:27 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1795FF8051E; Tue, 13 Jul 2021 16:29:52 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 A8059F804FF for ; Tue, 13 Jul 2021 16:29:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A8059F804FF Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="VtrSOIyE"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="p5o/pf3p" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7D33C22837 for ; Tue, 13 Jul 2021 14:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186573; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x0M9C7JIFCdVwEfvT+i1ktVRpUU4Ny5l0DvVLus9qE8=; b=VtrSOIyEfII/zhg2LxJ/DGWRwRnjMv93QbFTMuqN8mzTbhcpOpTZlYbI6zvnc5wqP9eHwo NQZiwYAXH5Zqb8ZOv+C9OT8OKRNE+2w9NuUomb6iXcbMT0yfLG3i2bXa38KiCmjYbgrDTX Uv0HcRXEUacu1xWExJYoKpdfizBSNSQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186573; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x0M9C7JIFCdVwEfvT+i1ktVRpUU4Ny5l0DvVLus9qE8=; b=p5o/pf3pg63O18TENg2YhKiYFkQortbsoS04pmYR5tWrArylj3+IlE83RVaOBAMiFFVEj4 LD/e1+9hdBrrd/AA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 6CD36A3B8A; Tue, 13 Jul 2021 14:29:33 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 30/51] ALSA: cs5535audio: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:36 +0200 Message-Id: <20210713142857.19654-31-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI cs5535audio 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. A slight uncertain change is the call of olpc_quirks_cleanup() at removal: formerly this was called unconditionally at remove, but this should be a conditionally call, hence the machine_is_olpc() check is added here as well. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/pci/cs5535audio/cs5535audio.c | 94 +++++------------------- sound/pci/cs5535audio/cs5535audio_olpc.c | 7 +- 2 files changed, 23 insertions(+), 78 deletions(-) diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c index e048b45d9e7e..499fa0148f9a 100644 --- a/sound/pci/cs5535audio/cs5535audio.c +++ b/sound/pci/cs5535audio/cs5535audio.c @@ -237,51 +237,24 @@ static irqreturn_t snd_cs5535audio_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static int snd_cs5535audio_free(struct cs5535audio *cs5535au) +static void snd_cs5535audio_free(struct snd_card *card) { - pci_set_power_state(cs5535au->pci, PCI_D3hot); - - if (cs5535au->irq >= 0) - free_irq(cs5535au->irq, cs5535au); - - pci_release_regions(cs5535au->pci); - pci_disable_device(cs5535au->pci); - kfree(cs5535au); - return 0; -} - -static int snd_cs5535audio_dev_free(struct snd_device *device) -{ - struct cs5535audio *cs5535au = device->device_data; - return snd_cs5535audio_free(cs5535au); + olpc_quirks_cleanup(); } static int snd_cs5535audio_create(struct snd_card *card, - struct pci_dev *pci, - struct cs5535audio **rcs5535au) + struct pci_dev *pci) { - struct cs5535audio *cs5535au; - + struct cs5535audio *cs5535au = card->private_data; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_cs5535audio_dev_free, - }; - *rcs5535au = 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(32))) { dev_warn(card->dev, "unable to get 32bit dma\n"); - err = -ENXIO; - goto pcifail; - } - - cs5535au = kzalloc(sizeof(*cs5535au), GFP_KERNEL); - if (cs5535au == NULL) { - err = -ENOMEM; - goto pcifail; + return -ENXIO; } spin_lock_init(&cs5535au->reg_lock); @@ -290,38 +263,22 @@ static int snd_cs5535audio_create(struct snd_card *card, cs5535au->irq = -1; err = pci_request_regions(pci, "CS5535 Audio"); - if (err < 0) { - kfree(cs5535au); - goto pcifail; - } + if (err < 0) + return err; cs5535au->port = pci_resource_start(pci, 0); - if (request_irq(pci->irq, snd_cs5535audio_interrupt, - IRQF_SHARED, KBUILD_MODNAME, cs5535au)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_cs5535audio_interrupt, + IRQF_SHARED, KBUILD_MODNAME, cs5535au)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - err = -EBUSY; - goto sndfail; + return -EBUSY; } cs5535au->irq = pci->irq; card->sync_irq = cs5535au->irq; pci_set_master(pci); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, cs5535au, &ops); - if (err < 0) - goto sndfail; - - *rcs5535au = cs5535au; return 0; - -sndfail: /* leave the device alive, just kill the snd */ - snd_cs5535audio_free(cs5535au); - return err; - -pcifail: - pci_disable_device(pci); - return err; } static int snd_cs5535audio_probe(struct pci_dev *pci, @@ -339,24 +296,24 @@ static int snd_cs5535audio_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(*cs5535au), &card); if (err < 0) return err; + cs5535au = card->private_data; + card->private_free = snd_cs5535audio_free; - err = snd_cs5535audio_create(card, pci, &cs5535au); + err = snd_cs5535audio_create(card, pci); if (err < 0) - goto probefail_out; - - card->private_data = cs5535au; + return err; err = snd_cs5535audio_mixer(cs5535au); if (err < 0) - goto probefail_out; + return err; err = snd_cs5535audio_pcm(cs5535au); if (err < 0) - goto probefail_out; + return err; strcpy(card->driver, DRIVER_NAME); @@ -367,28 +324,17 @@ static int snd_cs5535audio_probe(struct pci_dev *pci, err = snd_card_register(card); if (err < 0) - goto probefail_out; + return err; pci_set_drvdata(pci, card); dev++; return 0; - -probefail_out: - snd_card_free(card); - return err; -} - -static void snd_cs5535audio_remove(struct pci_dev *pci) -{ - olpc_quirks_cleanup(); - snd_card_free(pci_get_drvdata(pci)); } static struct pci_driver cs5535audio_driver = { .name = KBUILD_MODNAME, .id_table = snd_cs5535audio_ids, .probe = snd_cs5535audio_probe, - .remove = snd_cs5535audio_remove, #ifdef CONFIG_PM_SLEEP .driver = { .pm = &snd_cs5535audio_pm, diff --git a/sound/pci/cs5535audio/cs5535audio_olpc.c b/sound/pci/cs5535audio/cs5535audio_olpc.c index 110d3209441b..122170a410d9 100644 --- a/sound/pci/cs5535audio/cs5535audio_olpc.c +++ b/sound/pci/cs5535audio/cs5535audio_olpc.c @@ -171,10 +171,8 @@ int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) { err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i], ac97->private_data)); - if (err < 0) { - gpio_free(OLPC_GPIO_MIC_AC); + if (err < 0) return err; - } } /* turn off the mic by default */ @@ -184,5 +182,6 @@ int olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) void olpc_quirks_cleanup(void) { - gpio_free(OLPC_GPIO_MIC_AC); + if (machine_is_olpc()) + gpio_free(OLPC_GPIO_MIC_AC); } From patchwork Tue Jul 13 14:28:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474722 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=-18.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, USER_AGENT_GIT 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 10CB1C07E95 for ; Tue, 13 Jul 2021 14:41:43 +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 5C76C6115B for ; Tue, 13 Jul 2021 14:41:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C76C6115B 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 E7F89174A; Tue, 13 Jul 2021 16:40:50 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E7F89174A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187301; bh=05AkCagDvbKFCCICvLxDy4stNAkudTaYaLQ2wBjO04M=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=q41JC21ZF1q3GCbIdDp/t3e6PUij2s8mND843ZvPjns+pq+AVmeXuFAcIbMJJfvRh 4UIZeOLUhUAWhZINdcuUzejjHJPAUy5/iCwJDRLCzDXgLBO9SZoSrcAKs7Qow6K87V NM086lblVuR++RyyDffVY2IBpd5M3kmuEwjrUcm0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 600B1F805C9; Tue, 13 Jul 2021 16:30:37 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 37AC5F80589; Tue, 13 Jul 2021 16:29:55 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 60AACF8051B for ; Tue, 13 Jul 2021 16:29:34 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 60AACF8051B Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="VnEwgyXp"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="JBTnwGHt" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 3C4D722855 for ; Tue, 13 Jul 2021 14:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G2DCX/QEsG5SGmvCcP2ajlbmbwI490Kx3Vx7ceUZBTA=; b=VnEwgyXpoU/B1mwkg1QqzBEgynyiOfTFgHQJ/tn7mF3DngeETtTtEHa9+1tNmTfalmLu6L oDz5LXyoF+OMDUG9VLX1DIr6d5t1JhOtYcF6zRlodB6B3k/s82i8+2Znx2uR8MIzHhOBE2 Ss8iYzeVudCCWSbUQshIFb5IPuyRrms= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G2DCX/QEsG5SGmvCcP2ajlbmbwI490Kx3Vx7ceUZBTA=; b=JBTnwGHtzvQ7bIe6V+5t2tJL6IJabaWNfQZKTuQJB5iji5mKy6bviMICKIilcbyI8w0vGM e8WyIXNcI/i01nDg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 2A441A3B8D; Tue, 13 Jul 2021 14:29:34 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 31/51] ALSA: echoaudio: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:37 +0200 Message-Id: <20210713142857.19654-32-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI echoaudio drivers with devres as a clean up. Each manual resource management is converted with the corresponding devres helper, the page allocations are done with the devres helper, and the card object release is managed now via card->private_free instead of a lowlevel snd_device. The irq handler is still managed manually because it's re-acquired at PM suspend/resume. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/pci/echoaudio/echoaudio.c | 168 +++++++++----------------------- sound/pci/echoaudio/echoaudio.h | 2 +- 2 files changed, 48 insertions(+), 122 deletions(-) diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c index a62e5581ad14..25b012ef5c3e 100644 --- a/sound/pci/echoaudio/echoaudio.c +++ b/sound/pci/echoaudio/echoaudio.c @@ -1882,105 +1882,63 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id) Module construction / destruction ******************************************************************************/ -static int snd_echo_free(struct echoaudio *chip) +static void snd_echo_free(struct snd_card *card) { + struct echoaudio *chip = card->private_data; + if (chip->comm_page) rest_in_peace(chip); if (chip->irq >= 0) free_irq(chip->irq, chip); - if (chip->comm_page) - snd_dma_free_pages(&chip->commpage_dma_buf); - - iounmap(chip->dsp_registers); - release_and_free_resource(chip->iores); - pci_disable_device(chip->pci); - /* release chip data */ free_firmware_cache(chip); - kfree(chip); - return 0; -} - - - -static int snd_echo_dev_free(struct snd_device *device) -{ - struct echoaudio *chip = device->device_data; - - return snd_echo_free(chip); } - - /* <--snd_echo_probe() */ static int snd_echo_create(struct snd_card *card, - struct pci_dev *pci, - struct echoaudio **rchip) + struct pci_dev *pci) { - struct echoaudio *chip; + struct echoaudio *chip = card->private_data; int err; size_t sz; - static const struct snd_device_ops ops = { - .dev_free = snd_echo_dev_free, - }; - - *rchip = NULL; pci_write_config_byte(pci, PCI_LATENCY_TIMER, 0xC0); - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; pci_set_master(pci); /* Allocate chip if needed */ - if (!*rchip) { - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (!chip) { - pci_disable_device(pci); - return -ENOMEM; - } - dev_dbg(card->dev, "chip=%p\n", chip); - spin_lock_init(&chip->lock); - chip->card = card; - chip->pci = pci; - chip->irq = -1; - chip->opencount = 0; - mutex_init(&chip->mode_mutex); - chip->can_set_rate = 1; - } else { - /* If this was called from the resume function, chip is - * already allocated and it contains current card settings. - */ - chip = *rchip; - } + spin_lock_init(&chip->lock); + chip->card = card; + chip->pci = pci; + chip->irq = -1; + chip->opencount = 0; + mutex_init(&chip->mode_mutex); + chip->can_set_rate = 1; /* PCI resource allocation */ + err = pci_request_regions(pci, ECHOCARD_NAME); + if (err < 0) + return err; + chip->dsp_registers_phys = pci_resource_start(pci, 0); sz = pci_resource_len(pci, 0); if (sz > PAGE_SIZE) sz = PAGE_SIZE; /* We map only the required part */ - chip->iores = request_mem_region(chip->dsp_registers_phys, sz, - ECHOCARD_NAME); - if (!chip->iores) { - dev_err(chip->card->dev, "cannot get memory region\n"); - snd_echo_free(chip); - return -EBUSY; - } - chip->dsp_registers = ioremap(chip->dsp_registers_phys, sz); + chip->dsp_registers = devm_ioremap(&pci->dev, chip->dsp_registers_phys, sz); if (!chip->dsp_registers) { dev_err(chip->card->dev, "ioremap failed\n"); - snd_echo_free(chip); return -ENOMEM; } if (request_irq(pci->irq, snd_echo_interrupt, IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(chip->card->dev, "cannot grab irq\n"); - snd_echo_free(chip); return -EBUSY; } chip->irq = pci->irq; @@ -1988,39 +1946,29 @@ static int snd_echo_create(struct snd_card *card, dev_dbg(card->dev, "pci=%p irq=%d subdev=%04x Init hardware...\n", chip->pci, chip->irq, chip->pci->subsystem_device); + card->private_free = snd_echo_free; + /* Create the DSP comm page - this is the area of memory used for most of the communication with the DSP, which accesses it via bus mastering */ - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, - sizeof(struct comm_page), - &chip->commpage_dma_buf) < 0) { - dev_err(chip->card->dev, "cannot allocate the comm page\n"); - snd_echo_free(chip); + chip->commpage_dma_buf = + snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, + sizeof(struct comm_page)); + if (!chip->commpage_dma_buf) return -ENOMEM; - } - chip->comm_page_phys = chip->commpage_dma_buf.addr; - chip->comm_page = (struct comm_page *)chip->commpage_dma_buf.area; + chip->comm_page_phys = chip->commpage_dma_buf->addr; + chip->comm_page = (struct comm_page *)chip->commpage_dma_buf->area; err = init_hw(chip, chip->pci->device, chip->pci->subsystem_device); if (err >= 0) err = set_mixer_defaults(chip); if (err < 0) { dev_err(card->dev, "init_hw err=%d\n", err); - snd_echo_free(chip); return err; } - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_echo_free(chip); - return err; - } - *rchip = chip; - /* Init done ! */ return 0; } - - /* constructor */ static int snd_echo_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) @@ -2040,17 +1988,15 @@ static int snd_echo_probe(struct pci_dev *pci, } i = 0; - 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 = card->private_data; - chip = NULL; /* Tells snd_echo_create to allocate chip */ - err = snd_echo_create(card, pci, &chip); - if (err < 0) { - snd_card_free(card); + err = snd_echo_create(card, pci); + if (err < 0) return err; - } strcpy(card->driver, "Echo_" ECHOCARD_NAME); strcpy(card->shortname, chip->card_name); @@ -2066,7 +2012,6 @@ static int snd_echo_probe(struct pci_dev *pci, err = snd_echo_new_pcm(chip); if (err < 0) { dev_err(chip->card->dev, "new pcm error %d\n", err); - snd_card_free(card); return err; } @@ -2075,7 +2020,6 @@ static int snd_echo_probe(struct pci_dev *pci, err = snd_echo_midi_create(card, chip); if (err < 0) { dev_err(chip->card->dev, "new midi error %d\n", err); - snd_card_free(card); return err; } } @@ -2085,64 +2029,64 @@ static int snd_echo_probe(struct pci_dev *pci, snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip); err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip)); if (err < 0) - goto ctl_error; + return err; #ifdef ECHOCARD_HAS_LINE_OUT_GAIN err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_output_gain, chip)); if (err < 0) - goto ctl_error; + return err; #endif #else /* ECHOCARD_HAS_VMIXER */ err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip)); if (err < 0) - goto ctl_error; + return err; #endif /* ECHOCARD_HAS_VMIXER */ #ifdef ECHOCARD_HAS_INPUT_GAIN err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip)); if (err < 0) - goto ctl_error; + return err; #endif #ifdef ECHOCARD_HAS_INPUT_NOMINAL_LEVEL if (!chip->hasnt_input_nominal_level) { err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_intput_nominal_level, chip)); if (err < 0) - goto ctl_error; + return err; } #endif #ifdef ECHOCARD_HAS_OUTPUT_NOMINAL_LEVEL err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_output_nominal_level, chip)); if (err < 0) - goto ctl_error; + return err; #endif err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters_switch, chip)); if (err < 0) - goto ctl_error; + return err; err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vumeters, chip)); if (err < 0) - goto ctl_error; + return err; #ifdef ECHOCARD_HAS_MONITOR snd_echo_monitor_mixer.count = num_busses_in(chip) * num_busses_out(chip); err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_monitor_mixer, chip)); if (err < 0) - goto ctl_error; + return err; #endif #ifdef ECHOCARD_HAS_DIGITAL_IN_AUTOMUTE err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_automute_switch, chip)); if (err < 0) - goto ctl_error; + return err; #endif err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_channels_info, chip)); if (err < 0) - goto ctl_error; + return err; #ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH /* Creates a list of available digital modes */ @@ -2153,7 +2097,7 @@ static int snd_echo_probe(struct pci_dev *pci, err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_digital_mode_switch, chip)); if (err < 0) - goto ctl_error; + return err; #endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */ #ifdef ECHOCARD_HAS_EXTERNAL_CLOCK @@ -2167,37 +2111,32 @@ static int snd_echo_probe(struct pci_dev *pci, chip->clock_src_ctl = snd_ctl_new1(&snd_echo_clock_source_switch, chip); err = snd_ctl_add(chip->card, chip->clock_src_ctl); if (err < 0) - goto ctl_error; + return err; } #endif /* ECHOCARD_HAS_EXTERNAL_CLOCK */ #ifdef ECHOCARD_HAS_DIGITAL_IO err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_spdif_mode_switch, chip)); if (err < 0) - goto ctl_error; + return err; #endif #ifdef ECHOCARD_HAS_PHANTOM_POWER if (chip->has_phantom_power) { err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_phantom_power_switch, chip)); if (err < 0) - goto ctl_error; + return err; } #endif err = snd_card_register(card); if (err < 0) - goto ctl_error; + return err; dev_info(card->dev, "Card registered: %s\n", card->longname); pci_set_drvdata(pci, chip); dev++; return 0; - -ctl_error: - dev_err(card->dev, "new control error %d\n", err); - snd_card_free(card); - return err; } @@ -2299,18 +2238,6 @@ static SIMPLE_DEV_PM_OPS(snd_echo_pm, snd_echo_suspend, snd_echo_resume); #define SND_ECHO_PM_OPS NULL #endif /* CONFIG_PM_SLEEP */ - -static void snd_echo_remove(struct pci_dev *pci) -{ - struct echoaudio *chip; - - chip = pci_get_drvdata(pci); - if (chip) - snd_card_free(chip->card); -} - - - /****************************************************************************** Everything starts and ends here ******************************************************************************/ @@ -2320,7 +2247,6 @@ static struct pci_driver echo_driver = { .name = KBUILD_MODNAME, .id_table = snd_echo_ids, .probe = snd_echo_probe, - .remove = snd_echo_remove, .driver = { .pm = SND_ECHO_PM_OPS, }, diff --git a/sound/pci/echoaudio/echoaudio.h b/sound/pci/echoaudio/echoaudio.h index 0afe13f7b6e5..d51de3e4edfa 100644 --- a/sound/pci/echoaudio/echoaudio.h +++ b/sound/pci/echoaudio/echoaudio.h @@ -348,7 +348,7 @@ struct echoaudio { struct pci_dev *pci; unsigned long dsp_registers_phys; struct resource *iores; - struct snd_dma_buffer commpage_dma_buf; + struct snd_dma_buffer *commpage_dma_buf; int irq; #ifdef ECHOCARD_HAS_MIDI struct snd_rawmidi *rmidi; From patchwork Tue Jul 13 14:28:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474721 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=-18.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, USER_AGENT_GIT 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 7BCDDC07E95 for ; Tue, 13 Jul 2021 14:43:00 +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 9967C61289 for ; Tue, 13 Jul 2021 14:42:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9967C61289 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 D49511727; Tue, 13 Jul 2021 16:42:07 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D49511727 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187377; bh=F5y1crdpP6cv74GNcBicqAssaP3F1QQ+7EsaEaML/K4=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Puy7eyxMNXfFyUJBjykaxPpx3K0CGbWVBe6tZY7O9z4opFMUlQZM3OpKsgWHs2bwS dANyL7Ig5zPM1i3d8uPdNM6nweUVcx8J39LgyLrkn4RlO2vcpOVmdXDLwUxALPVIsP ghzOGQKJJmEM9FT3iDiehURbdqncdYBDkcuJfwwI= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 618B0F805F2; Tue, 13 Jul 2021 16:30:48 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 20274F80525; Tue, 13 Jul 2021 16:29:56 +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 24F05F80508 for ; Tue, 13 Jul 2021 16:29:35 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 24F05F80508 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="RAd1Oq4m"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="1AQ3tGyK" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id EE323201DA for ; Tue, 13 Jul 2021 14:29:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tzlv32loXGZtJmQcuqUnxjn9bVEdumHl6RLnpXoIf9I=; b=RAd1Oq4mcYUcyrgQIVI9A6UAdbVLNHrADcaA5mTQLr+cWD5NquanuXcPD1RTluDBu9qO04 O7oCQuzaf+4CI/JuEDHQtZhl56hQjvkAeq73jbeKReYyUagXSgfgSPtkyRZEFN09mL8wBx b1/8hcoA6rh8g/6BUwzq9MnpoOiRmfE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186574; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tzlv32loXGZtJmQcuqUnxjn9bVEdumHl6RLnpXoIf9I=; b=1AQ3tGyKtpjc+yD6Jw2r6jLfPSOs6KCijTZwhMefOHnhEDvK+YRygyZAmF5kYNz58Ge4fn Mh1Ulah/NFgxzECw== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id DBF14A3B8E; Tue, 13 Jul 2021 14:29:34 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 32/51] ALSA: emu10k1: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:38 +0200 Message-Id: <20210713142857.19654-33-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI emu10k1 driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper, the page allocations are done with the 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 --- include/sound/emu10k1.h | 6 +- sound/pci/emu10k1/emu10k1.c | 53 +++++++--------- sound/pci/emu10k1/emu10k1_main.c | 102 ++++++++----------------------- sound/pci/emu10k1/p16v.c | 22 ++----- 4 files changed, 52 insertions(+), 131 deletions(-) diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h index 468e38c54dd3..39787fecc8d9 100644 --- a/include/sound/emu10k1.h +++ b/include/sound/emu10k1.h @@ -1701,7 +1701,7 @@ struct snd_emu10k1 { struct snd_dma_buffer silent_page; /* silent page */ struct snd_dma_buffer ptb_pages; /* page table pages */ struct snd_dma_device p16v_dma_dev; - struct snd_dma_buffer p16v_buffer; + struct snd_dma_buffer *p16v_buffer; struct snd_util_memhdr *memhdr; /* page allocation list */ @@ -1796,14 +1796,12 @@ int snd_emu10k1_create(struct snd_card *card, unsigned short extout_mask, long max_cache_bytes, int enable_ir, - uint subsystem, - struct snd_emu10k1 ** remu); + uint subsystem); int snd_emu10k1_pcm(struct snd_emu10k1 *emu, int device); int snd_emu10k1_pcm_mic(struct snd_emu10k1 *emu, int device); int snd_emu10k1_pcm_efx(struct snd_emu10k1 *emu, int device); int snd_p16v_pcm(struct snd_emu10k1 *emu, int device); -int snd_p16v_free(struct snd_emu10k1 * emu); int snd_p16v_mixer(struct snd_emu10k1 * emu); int snd_emu10k1_pcm_multi(struct snd_emu10k1 *emu, int device); int snd_emu10k1_fx8010_pcm(struct snd_emu10k1 *emu, int device); diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c index 887bfb3c1e17..672af4b9597b 100644 --- a/sound/pci/emu10k1/emu10k1.c +++ b/sound/pci/emu10k1/emu10k1.c @@ -99,67 +99,67 @@ static int snd_card_emu10k1_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(*emu), &card); if (err < 0) return err; + emu = card->private_data; + if (max_buffer_size[dev] < 32) max_buffer_size[dev] = 32; else if (max_buffer_size[dev] > 1024) max_buffer_size[dev] = 1024; err = snd_emu10k1_create(card, pci, extin[dev], extout[dev], (long)max_buffer_size[dev] * 1024 * 1024, - enable_ir[dev], subsystem[dev], - &emu); + enable_ir[dev], subsystem[dev]); if (err < 0) - goto error; - card->private_data = emu; + return err; emu->delay_pcm_irq = delay_pcm_irq[dev] & 0x1f; err = snd_emu10k1_pcm(emu, 0); if (err < 0) - goto error; + return err; err = snd_emu10k1_pcm_mic(emu, 1); if (err < 0) - goto error; + return err; err = snd_emu10k1_pcm_efx(emu, 2); if (err < 0) - goto error; + return err; /* This stores the periods table. */ if (emu->card_capabilities->ca0151_chip) { /* P16V */ - err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, - 1024, &emu->p16v_buffer); - if (err < 0) - goto error; + emu->p16v_buffer = + snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, 1024); + if (!emu->p16v_buffer) + return -ENOMEM; } err = snd_emu10k1_mixer(emu, 0, 3); if (err < 0) - goto error; + return err; err = snd_emu10k1_timer(emu, 0); if (err < 0) - goto error; + return err; err = snd_emu10k1_pcm_multi(emu, 3); if (err < 0) - goto error; + return err; if (emu->card_capabilities->ca0151_chip) { /* P16V */ err = snd_p16v_pcm(emu, 4); if (err < 0) - goto error; + return err; } if (emu->audigy) { err = snd_emu10k1_audigy_midi(emu); if (err < 0) - goto error; + return err; } else { err = snd_emu10k1_midi(emu); if (err < 0) - goto error; + return err; } err = snd_emu10k1_fx8010_new(emu, 0); if (err < 0) - goto error; + return err; #ifdef ENABLE_SYNTH if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, sizeof(struct snd_emu10k1_synth_arg), &wave) < 0 || @@ -187,7 +187,7 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci, err = snd_card_register(card); if (err < 0) - goto error; + return err; if (emu->card_capabilities->emu_model) schedule_delayed_work(&emu->emu1010.firmware_work, 0); @@ -195,18 +195,8 @@ static int snd_card_emu10k1_probe(struct pci_dev *pci, pci_set_drvdata(pci, card); dev++; return 0; - - error: - snd_card_free(card); - return err; } -static void snd_card_emu10k1_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - - #ifdef CONFIG_PM_SLEEP static int snd_emu10k1_suspend(struct device *dev) { @@ -263,7 +253,6 @@ static struct pci_driver emu10k1_driver = { .name = KBUILD_MODNAME, .id_table = snd_emu10k1_ids, .probe = snd_card_emu10k1_probe, - .remove = snd_card_emu10k1_remove, .driver = { .pm = SND_EMU10K1_PM_OPS, }, diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c index 24a2fd706d69..86cc1ca025e4 100644 --- a/sound/pci/emu10k1/emu10k1_main.c +++ b/sound/pci/emu10k1/emu10k1_main.c @@ -1242,8 +1242,10 @@ static int alloc_pm_buffer(struct snd_emu10k1 *emu); static void free_pm_buffer(struct snd_emu10k1 *emu); #endif -static int snd_emu10k1_free(struct snd_emu10k1 *emu) +static void snd_emu10k1_free(struct snd_card *card) { + struct snd_emu10k1 *emu = card->private_data; + if (emu->port) { /* avoid access to already used hardware */ snd_emu10k1_fx8010_tram_setup(emu, 0); snd_emu10k1_done(emu); @@ -1256,8 +1258,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) cancel_delayed_work_sync(&emu->emu1010.firmware_work); release_firmware(emu->firmware); release_firmware(emu->dock_fw); - if (emu->irq >= 0) - free_irq(emu->irq, emu); snd_util_memhdr_free(emu->memhdr); if (emu->silent_page.area) snd_dma_free_pages(&emu->silent_page); @@ -1268,19 +1268,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu) #ifdef CONFIG_PM_SLEEP free_pm_buffer(emu); #endif - if (emu->port) - pci_release_regions(emu->pci); - if (emu->card_capabilities->ca0151_chip) /* P16V */ - snd_p16v_free(emu); - pci_disable_device(emu->pci); - kfree(emu); - return 0; -} - -static int snd_emu10k1_dev_free(struct snd_device *device) -{ - struct snd_emu10k1 *emu = device->device_data; - return snd_emu10k1_free(emu); } static const struct snd_emu_chip_details emu_chip_details[] = { @@ -1782,32 +1769,22 @@ int snd_emu10k1_create(struct snd_card *card, unsigned short extout_mask, long max_cache_bytes, int enable_ir, - uint subsystem, - struct snd_emu10k1 **remu) + uint subsystem) { - struct snd_emu10k1 *emu; + struct snd_emu10k1 *emu = card->private_data; int idx, err; int is_audigy; size_t page_table_size; __le32 *pgtbl; unsigned int silent_page; const struct snd_emu_chip_details *c; - static const struct snd_device_ops ops = { - .dev_free = snd_emu10k1_dev_free, - }; - - *remu = NULL; /* enable PCI device */ - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - emu = kzalloc(sizeof(*emu), GFP_KERNEL); - if (emu == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } + card->private_free = snd_emu10k1_free; emu->card = card; spin_lock_init(&emu->reg_lock); spin_lock_init(&emu->emu_lock); @@ -1850,8 +1827,6 @@ int snd_emu10k1_create(struct snd_card *card, } if (c->vendor == 0) { dev_err(card->dev, "emu10k1: Card not recognised\n"); - kfree(emu); - pci_disable_device(pci); return -ENOENT; } emu->card_capabilities = c; @@ -1883,8 +1858,6 @@ int snd_emu10k1_create(struct snd_card *card, dev_err(card->dev, "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask); - kfree(emu); - pci_disable_device(pci); return -ENXIO; } if (is_audigy) @@ -1893,11 +1866,8 @@ int snd_emu10k1_create(struct snd_card *card, emu->gpr_base = FXGPREGBASE; err = pci_request_regions(pci, "EMU10K1"); - if (err < 0) { - kfree(emu); - pci_disable_device(pci); + if (err < 0) return err; - } emu->port = pci_resource_start(pci, 0); emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT; @@ -1905,10 +1875,8 @@ int snd_emu10k1_create(struct snd_card *card, page_table_size = sizeof(u32) * (emu->address_mode ? MAXPAGES1 : MAXPAGES0); if (snd_emu10k1_alloc_pages_maybe_wider(emu, page_table_size, - &emu->ptb_pages) < 0) { - err = -ENOMEM; - goto error; - } + &emu->ptb_pages) < 0) + return -ENOMEM; dev_dbg(card->dev, "page table address range is %.8lx:%.8lx\n", (unsigned long)emu->ptb_pages.addr, (unsigned long)(emu->ptb_pages.addr + emu->ptb_pages.bytes)); @@ -1917,26 +1885,20 @@ int snd_emu10k1_create(struct snd_card *card, emu->max_cache_pages)); emu->page_addr_table = vmalloc(array_size(sizeof(unsigned long), emu->max_cache_pages)); - if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) { - err = -ENOMEM; - goto error; - } + if (!emu->page_ptr_table || !emu->page_addr_table) + return -ENOMEM; if (snd_emu10k1_alloc_pages_maybe_wider(emu, EMUPAGESIZE, - &emu->silent_page) < 0) { - err = -ENOMEM; - goto error; - } + &emu->silent_page) < 0) + return -ENOMEM; dev_dbg(card->dev, "silent page range is %.8lx:%.8lx\n", (unsigned long)emu->silent_page.addr, (unsigned long)(emu->silent_page.addr + emu->silent_page.bytes)); emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE); - if (emu->memhdr == NULL) { - err = -ENOMEM; - goto error; - } + if (!emu->memhdr) + return -ENOMEM; emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) - sizeof(struct snd_util_memblk); @@ -1954,18 +1916,16 @@ int snd_emu10k1_create(struct snd_card *card, if (emu->card_capabilities->ca_cardbus_chip) { err = snd_emu10k1_cardbus_init(emu); if (err < 0) - goto error; + return err; } if (emu->card_capabilities->ecard) { err = snd_emu10k1_ecard_init(emu); if (err < 0) - goto error; + return err; } else if (emu->card_capabilities->emu_model) { err = snd_emu10k1_emu1010_init(emu); - if (err < 0) { - snd_emu10k1_free(emu); + if (err < 0) return err; - } } else { /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version does not support this, it shouldn't do any harm */ @@ -1979,11 +1939,9 @@ int snd_emu10k1_create(struct snd_card *card, emu->fx8010.etram_pages.bytes = 0; /* irq handler must be registered after I/O ports are activated */ - if (request_irq(pci->irq, snd_emu10k1_interrupt, IRQF_SHARED, - KBUILD_MODNAME, emu)) { - err = -EBUSY; - goto error; - } + if (devm_request_irq(&pci->dev, pci->irq, snd_emu10k1_interrupt, + IRQF_SHARED, KBUILD_MODNAME, emu)) + return -EBUSY; emu->irq = pci->irq; card->sync_irq = emu->irq; @@ -2022,33 +1980,23 @@ int snd_emu10k1_create(struct snd_card *card, err = snd_emu10k1_init(emu, enable_ir, 0); if (err < 0) - goto error; + return err; #ifdef CONFIG_PM_SLEEP err = alloc_pm_buffer(emu); if (err < 0) - goto error; + return err; #endif /* Initialize the effect engine */ err = snd_emu10k1_init_efx(emu); if (err < 0) - goto error; + return err; snd_emu10k1_audio_enable(emu); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops); - if (err < 0) - goto error; - #ifdef CONFIG_SND_PROC_FS snd_emu10k1_proc_init(emu); #endif - - *remu = emu; return 0; - - error: - snd_emu10k1_free(emu); - return err; } #ifdef CONFIG_PM_SLEEP diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c index ff2a3974c824..18a1b0740e6b 100644 --- a/sound/pci/emu10k1/p16v.c +++ b/sound/pci/emu10k1/p16v.c @@ -290,7 +290,7 @@ static int snd_p16v_pcm_prepare_playback(struct snd_pcm_substream *substream) struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; int channel = substream->pcm->device - emu->p16v_device_offset; - u32 *table_base = (u32 *)(emu->p16v_buffer.area+(8*16*channel)); + u32 *table_base = (u32 *)(emu->p16v_buffer->area+(8*16*channel)); u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size); int i; u32 tmp; @@ -308,8 +308,8 @@ static int snd_p16v_pcm_prepare_playback(struct snd_pcm_substream *substream) runtime->dma_addr, runtime->dma_area, table_base); dev_dbg(emu->card->dev, "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n", - emu->p16v_buffer.addr, emu->p16v_buffer.area, - emu->p16v_buffer.bytes); + emu->p16v_buffer->addr, emu->p16v_buffer->area, + emu->p16v_buffer->bytes); #endif /* debug */ tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel); switch (runtime->rate) { @@ -333,7 +333,7 @@ static int snd_p16v_pcm_prepare_playback(struct snd_pcm_substream *substream) table_base[(i*2)+1]=period_size_bytes<<16; } - snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_ADDR, channel, emu->p16v_buffer.addr+(8*16*channel)); + snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_ADDR, channel, emu->p16v_buffer->addr+(8*16*channel)); snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19); snd_emu10k1_ptr20_write(emu, PLAYBACK_LIST_PTR, channel, 0); snd_emu10k1_ptr20_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr); @@ -567,20 +567,6 @@ static const struct snd_pcm_ops snd_p16v_capture_ops = { .pointer = snd_p16v_pcm_pointer_capture, }; - -int snd_p16v_free(struct snd_emu10k1 *chip) -{ - // release the data - if (chip->p16v_buffer.area) { - snd_dma_free_pages(&chip->p16v_buffer); - /* - dev_dbg(chip->card->dev, "period lables free: %p\n", - &chip->p16v_buffer); - */ - } - return 0; -} - int snd_p16v_pcm(struct snd_emu10k1 *emu, int device) { struct snd_pcm *pcm; From patchwork Tue Jul 13 14:28:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474719 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=-18.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, USER_AGENT_GIT 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 146B8C07E95 for ; Tue, 13 Jul 2021 14:44:40 +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 9185760E0B for ; Tue, 13 Jul 2021 14:44:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9185760E0B 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 2B9C916E1; Tue, 13 Jul 2021 16:43:48 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2B9C916E1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187478; bh=yinoVpqHxEtfVFvUbQnGSWyjU6qLhovuCSgOHV/63ro=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=L/hTYsdpQA0Lv0Naae03HvYvjAbmqP5eROFo6/LHgrUN7c4l4laMLCBwmPflLAGpf xuCBj8DAstUG1e8dJlw38rGSGIEg0GVY6GKjcom1uzhp6nU+L6dWKa80+auJl66fyP AG3WdXocd8FCt3+PhbEGkQx6RaigD+vUVWIztMSU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 92387F8060D; Tue, 13 Jul 2021 16:30:51 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 48E3CF80515; Tue, 13 Jul 2021 16:30:01 +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 3F129F80515 for ; Tue, 13 Jul 2021 16:29:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3F129F80515 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="sE2eH0l7"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="X98P4BNK" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 10547201E4 for ; Tue, 13 Jul 2021 14:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yqc3z8b/mRbzn+Osqv1WrJQcGHc6KAh7H2dy+A+vKvY=; b=sE2eH0l7yxQ/zXy8cWnSU4N8FQYi1VbKEVLeBninEnPp5VtqLqpidBTi5thtun/wwHIspD p977RDjuj+rW1SpymrE475+EvJP86onHtjdbUVe1N2YVuPXPIzIag/m5Lfy1mz67YUvXQP T/eI0eBGvZJgf969omSAXrIKxsaPgyY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yqc3z8b/mRbzn+Osqv1WrJQcGHc6KAh7H2dy+A+vKvY=; b=X98P4BNK8I2Zxgj9uzqEFLqXxMWbjTa7GLxaFijcSALu9FvQUYtSHKCb443UyjctUxglwt q6sHFs8qfD1DLCBw== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 099A9A3B83; Tue, 13 Jul 2021 14:29:37 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 35/51] ALSA: ice1724: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:41 +0200 Message-Id: <20210713142857.19654-36-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI ice1724 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. Along with it, the chip_exit callback chain is moved into the card's private_free instead of the PCI remove callback, too. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/pci/ice1712/ice1724.c | 127 ++++++++---------------------------- 1 file changed, 27 insertions(+), 100 deletions(-) diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c index 8052d7cb8925..1cd84f9338f3 100644 --- a/sound/pci/ice1712/ice1724.c +++ b/sound/pci/ice1712/ice1724.c @@ -2447,54 +2447,29 @@ static int snd_vt1724_build_controls(struct snd_ice1712 *ice) snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice)); } -static int snd_vt1724_free(struct snd_ice1712 *ice) +static void snd_vt1724_free(struct snd_card *card) { - if (!ice->port) - goto __hw_end; + struct snd_ice1712 *ice = card->private_data; + /* mask all interrupts */ outb(0xff, ICEMT1724(ice, DMA_INT_MASK)); outb(0xff, ICEREG1724(ice, IRQMASK)); - /* --- */ -__hw_end: - if (ice->irq >= 0) - free_irq(ice->irq, ice); - pci_release_regions(ice->pci); - snd_ice1712_akm4xxx_free(ice); - pci_disable_device(ice->pci); - kfree(ice->spec); - kfree(ice); - return 0; -} -static int snd_vt1724_dev_free(struct snd_device *device) -{ - struct snd_ice1712 *ice = device->device_data; - return snd_vt1724_free(ice); + snd_ice1712_akm4xxx_free(ice); } static int snd_vt1724_create(struct snd_card *card, struct pci_dev *pci, - const char *modelname, - struct snd_ice1712 **r_ice1712) + const char *modelname) { struct snd_ice1712 *ice; int err; - static const struct snd_device_ops ops = { - .dev_free = snd_vt1724_dev_free, - }; - - *r_ice1712 = NULL; /* enable PCI device */ - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - ice = kzalloc(sizeof(*ice), GFP_KERNEL); - if (ice == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } ice->vt1724 = 1; spin_lock_init(&ice->reg_lock); mutex_init(&ice->gpio_mutex); @@ -2512,44 +2487,28 @@ static int snd_vt1724_create(struct snd_card *card, pci_set_master(pci); snd_vt1724_proc_init(ice); - card->private_data = ice; - err = pci_request_regions(pci, "ICE1724"); - if (err < 0) { - kfree(ice); - pci_disable_device(pci); + if (err < 0) return err; - } ice->port = pci_resource_start(pci, 0); ice->profi_port = pci_resource_start(pci, 1); - if (request_irq(pci->irq, snd_vt1724_interrupt, - IRQF_SHARED, KBUILD_MODNAME, ice)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_vt1724_interrupt, + IRQF_SHARED, KBUILD_MODNAME, ice)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_vt1724_free(ice); return -EIO; } ice->irq = pci->irq; card->sync_irq = ice->irq; + card->private_free = snd_vt1724_free; snd_vt1724_chip_reset(ice); - if (snd_vt1724_read_eeprom(ice, modelname) < 0) { - snd_vt1724_free(ice); + if (snd_vt1724_read_eeprom(ice, modelname) < 0) return -EIO; - } - if (snd_vt1724_chip_init(ice) < 0) { - snd_vt1724_free(ice); + if (snd_vt1724_chip_init(ice) < 0) return -EIO; - } - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops); - if (err < 0) { - snd_vt1724_free(ice); - return err; - } - - *r_ice1712 = ice; return 0; } @@ -2576,19 +2535,18 @@ static int snd_vt1724_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(*ice), &card); if (err < 0) return err; + ice = card->private_data; strcpy(card->driver, "ICE1724"); strcpy(card->shortname, "ICEnsemble ICE1724"); - err = snd_vt1724_create(card, pci, model[dev], &ice); - if (err < 0) { - snd_card_free(card); + err = snd_vt1724_create(card, pci, model[dev]); + if (err < 0) return err; - } /* field init before calling chip_init */ ice->ext_clock_count = 0; @@ -2600,10 +2558,8 @@ static int snd_vt1724_probe(struct pci_dev *pci, strcpy(card->driver, c->driver); if (c->chip_init) { err = c->chip_init(ice); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } } } @@ -2637,49 +2593,35 @@ static int snd_vt1724_probe(struct pci_dev *pci, set_std_hw_rates(ice); err = snd_vt1724_pcm_profi(ice, pcm_dev++); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_vt1724_pcm_spdif(ice, pcm_dev++); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_vt1724_pcm_indep(ice, pcm_dev++); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_vt1724_ac97_mixer(ice); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } err = snd_vt1724_build_controls(ice); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */ err = snd_vt1724_spdif_build_controls(ice); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } } if (c && c->build_controls) { err = c->build_controls(ice); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } } if (!c || !c->no_mpu401) { @@ -2687,10 +2629,8 @@ static int snd_vt1724_probe(struct pci_dev *pci, struct snd_rawmidi *rmidi; err = snd_rawmidi_new(card, "MIDI", 0, 1, 1, &rmidi); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } ice->rmidi[0] = rmidi; rmidi->private_data = ice; strcpy(rmidi->name, "ICE1724 MIDI"); @@ -2715,25 +2655,13 @@ static int snd_vt1724_probe(struct pci_dev *pci, card->shortname, ice->port, ice->irq); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_vt1724_remove(struct pci_dev *pci) -{ - struct snd_card *card = pci_get_drvdata(pci); - struct snd_ice1712 *ice = card->private_data; - - if (ice->card_info && ice->card_info->chip_exit) - ice->card_info->chip_exit(ice); - snd_card_free(card); -} - #ifdef CONFIG_PM_SLEEP static int snd_vt1724_suspend(struct device *dev) { @@ -2811,7 +2739,6 @@ static struct pci_driver vt1724_driver = { .name = KBUILD_MODNAME, .id_table = snd_vt1724_ids, .probe = snd_vt1724_probe, - .remove = snd_vt1724_remove, .driver = { .pm = SND_VT1724_PM_OPS, }, From patchwork Tue Jul 13 14:28:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474720 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=-18.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, USER_AGENT_GIT 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 6E0F4C07E96 for ; Tue, 13 Jul 2021 14:44:01 +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 8EDD361289 for ; Tue, 13 Jul 2021 14:44:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8EDD361289 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 24E90172E; Tue, 13 Jul 2021 16:43:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 24E90172E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187439; bh=oeR6i+uFUwsCmUJ0zHdNC/j7IGFXm8A5+Zi1PePtcz4=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YvRF6v5pDxoQWT/1tDWD2NWgnV4SKsGatePYy+iDDWrhHsgeU3rZtUpeOu0tXYMKC CZM+8yMElvK7DG7uH/hjcKNw1jHW8TZzKJyykzs7Qed7TCADhK55sKAAKk4V7vNoMG pUl7G4slX5VVLioLpVP8F/rL63f47kKK3TLXIAjU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 8B4FFF80605; Tue, 13 Jul 2021 16:30:50 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2C4F1F8052E; Tue, 13 Jul 2021 16:30:00 +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 0D744F80518 for ; Tue, 13 Jul 2021 16:29:37 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 0D744F80518 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Mees7mfO"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="9NyGKck/" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id C7DC1201E5 for ; Tue, 13 Jul 2021 14:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tVSYCtA/9mDhb6inb5s+c97+UjZmWRkAMNL7BQan+JI=; b=Mees7mfO/l+HotCdJBkV1UtZyiFtdQH6OholDABavFTcDrG6kIovOHnyBgGMAuF3FG6WcV BJJoY7hK1I6oASiDkfjsZf4prlABvQ87fUIGhRoBdi+GkAy7cplYw9AhWTUspdqJqWkP8b pIpAWxXF5XHfTKPCAoTRHBnBkQKuH38= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186577; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tVSYCtA/9mDhb6inb5s+c97+UjZmWRkAMNL7BQan+JI=; b=9NyGKck/GEHgZ/UIDk5x9a8Lm8ArcjaUBM/VQ6dgygeBytcGRgiDRiiXXfRWqc953dIHdw Osyu/pdtTYBbUpDg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id B5314A3B88; Tue, 13 Jul 2021 14:29:37 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 36/51] ALSA: korg1212: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:42 +0200 Message-Id: <20210713142857.19654-37-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI korg1212 driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper, the page allocations are done with the 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/korg1212/korg1212.c | 211 +++++++++------------------------- 1 file changed, 55 insertions(+), 156 deletions(-) diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c index 030e01b062e4..7872abbd4587 100644 --- a/sound/pci/korg1212/korg1212.c +++ b/sound/pci/korg1212/korg1212.c @@ -320,10 +320,10 @@ struct snd_korg1212 { unsigned long inIRQ; void __iomem *iobase; - struct snd_dma_buffer dma_dsp; - struct snd_dma_buffer dma_play; - struct snd_dma_buffer dma_rec; - struct snd_dma_buffer dma_shared; + struct snd_dma_buffer *dma_dsp; + struct snd_dma_buffer *dma_play; + struct snd_dma_buffer *dma_rec; + struct snd_dma_buffer *dma_shared; u32 DataBufsSize; @@ -1200,8 +1200,8 @@ static int snd_korg1212_downloadDSPCode(struct snd_korg1212 *korg1212) snd_korg1212_setCardState(korg1212, K1212_STATE_DSP_IN_PROCESS); rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_StartDSPDownload, - UpperWordSwap(korg1212->dma_dsp.addr), - 0, 0, 0); + UpperWordSwap(korg1212->dma_dsp->addr), + 0, 0, 0); if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Start DSP Download RC = %d [%s]\n", rc, stateName[korg1212->cardState]); @@ -1382,7 +1382,7 @@ static int snd_korg1212_playback_open(struct snd_pcm_substream *substream) snd_korg1212_OpenCard(korg1212); runtime->hw = snd_korg1212_playback_info; - snd_pcm_set_runtime_buffer(substream, &korg1212->dma_play); + snd_pcm_set_runtime_buffer(substream, korg1212->dma_play); spin_lock_irqsave(&korg1212->lock, flags); @@ -1413,7 +1413,7 @@ static int snd_korg1212_capture_open(struct snd_pcm_substream *substream) snd_korg1212_OpenCard(korg1212); runtime->hw = snd_korg1212_capture_info; - snd_pcm_set_runtime_buffer(substream, &korg1212->dma_rec); + snd_pcm_set_runtime_buffer(substream, korg1212->dma_rec); spin_lock_irqsave(&korg1212->lock, flags); @@ -2080,71 +2080,16 @@ static void snd_korg1212_proc_init(struct snd_korg1212 *korg1212) snd_korg1212_proc_read); } -static int -snd_korg1212_free(struct snd_korg1212 *korg1212) +static void +snd_korg1212_free(struct snd_card *card) { - snd_korg1212_TurnOffIdleMonitor(korg1212); - - if (korg1212->irq >= 0) { - snd_korg1212_DisableCardInterrupts(korg1212); - free_irq(korg1212->irq, korg1212); - korg1212->irq = -1; - } - - if (korg1212->iobase != NULL) { - iounmap(korg1212->iobase); - korg1212->iobase = NULL; - } - - pci_release_regions(korg1212->pci); - - // ---------------------------------------------------- - // free up memory resources used for the DSP download. - // ---------------------------------------------------- - if (korg1212->dma_dsp.area) { - snd_dma_free_pages(&korg1212->dma_dsp); - korg1212->dma_dsp.area = NULL; - } - -#ifndef K1212_LARGEALLOC - - // ------------------------------------------------------ - // free up memory resources used for the Play/Rec Buffers - // ------------------------------------------------------ - if (korg1212->dma_play.area) { - snd_dma_free_pages(&korg1212->dma_play); - korg1212->dma_play.area = NULL; - } + struct snd_korg1212 *korg1212 = card->private_data; - if (korg1212->dma_rec.area) { - snd_dma_free_pages(&korg1212->dma_rec); - korg1212->dma_rec.area = NULL; - } - -#endif - - // ---------------------------------------------------- - // free up memory resources used for the Shared Buffers - // ---------------------------------------------------- - if (korg1212->dma_shared.area) { - snd_dma_free_pages(&korg1212->dma_shared); - korg1212->dma_shared.area = NULL; - } - - pci_disable_device(korg1212->pci); - kfree(korg1212); - return 0; -} - -static int snd_korg1212_dev_free(struct snd_device *device) -{ - struct snd_korg1212 *korg1212 = device->device_data; - K1212_DEBUG_PRINTK("K1212_DEBUG: Freeing device\n"); - return snd_korg1212_free(korg1212); + snd_korg1212_TurnOffIdleMonitor(korg1212); + snd_korg1212_DisableCardInterrupts(korg1212); } -static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, - struct snd_korg1212 **rchip) +static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci) { int err, rc; @@ -2152,24 +2097,13 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, unsigned iomem_size; __maybe_unused unsigned ioport_size; __maybe_unused unsigned iomem2_size; - struct snd_korg1212 * korg1212; + struct snd_korg1212 *korg1212 = card->private_data; const struct firmware *dsp_code; - static const struct snd_device_ops ops = { - .dev_free = snd_korg1212_dev_free, - }; - - * rchip = NULL; - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - korg1212 = kzalloc(sizeof(*korg1212), GFP_KERNEL); - if (korg1212 == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } - korg1212->card = card; korg1212->pci = pci; @@ -2198,12 +2132,9 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, for (i=0; ivolumePhase[i] = 0; - err = pci_request_regions(pci, "korg1212"); - if (err < 0) { - kfree(korg1212); - pci_disable_device(pci); + err = pcim_iomap_regions_request_all(pci, 1 << 0, "korg1212"); + if (err < 0) return err; - } korg1212->iomem = pci_resource_start(korg1212->pci, 0); korg1212->ioport = pci_resource_start(korg1212->pci, 1); @@ -2223,26 +2154,20 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, korg1212->iomem2, iomem2_size, stateName[korg1212->cardState]); - korg1212->iobase = ioremap(korg1212->iomem, iomem_size); - if (!korg1212->iobase) { - snd_printk(KERN_ERR "korg1212: unable to remap memory region 0x%lx-0x%lx\n", korg1212->iomem, - korg1212->iomem + iomem_size - 1); - snd_korg1212_free(korg1212); - return -EBUSY; - } + korg1212->iobase = pcim_iomap_table(pci)[0]; - err = request_irq(pci->irq, snd_korg1212_interrupt, + err = devm_request_irq(&pci->dev, pci->irq, snd_korg1212_interrupt, IRQF_SHARED, KBUILD_MODNAME, korg1212); if (err) { snd_printk(KERN_ERR "korg1212: unable to grab IRQ %d\n", pci->irq); - snd_korg1212_free(korg1212); return -EBUSY; } korg1212->irq = pci->irq; card->sync_irq = korg1212->irq; + card->private_free = snd_korg1212_free; pci_set_master(korg1212->pci); @@ -2281,41 +2206,36 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, korg1212->idRegPtr, stateName[korg1212->cardState]); - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, - sizeof(struct KorgSharedBuffer), &korg1212->dma_shared) < 0) { - snd_printk(KERN_ERR "korg1212: can not allocate shared buffer memory (%zd bytes)\n", sizeof(struct KorgSharedBuffer)); - snd_korg1212_free(korg1212); - return -ENOMEM; - } - korg1212->sharedBufferPtr = (struct KorgSharedBuffer *)korg1212->dma_shared.area; - korg1212->sharedBufferPhy = korg1212->dma_shared.addr; + korg1212->dma_shared = snd_devm_alloc_pages(&pci->dev, + SNDRV_DMA_TYPE_DEV, + sizeof(struct KorgSharedBuffer)); + if (!korg1212->dma_shared) + return -ENOMEM; + korg1212->sharedBufferPtr = (struct KorgSharedBuffer *)korg1212->dma_shared->area; + korg1212->sharedBufferPhy = korg1212->dma_shared->addr; K1212_DEBUG_PRINTK("K1212_DEBUG: Shared Buffer Area = 0x%p (0x%08lx), %d bytes\n", korg1212->sharedBufferPtr, korg1212->sharedBufferPhy, sizeof(struct KorgSharedBuffer)); #ifndef K1212_LARGEALLOC - korg1212->DataBufsSize = sizeof(struct KorgAudioBuffer) * kNumBuffers; + korg1212->dma_play = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, + korg1212->DataBufsSize); + if (!korg1212->dma_play) + return -ENOMEM; - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, - korg1212->DataBufsSize, &korg1212->dma_play) < 0) { - snd_printk(KERN_ERR "korg1212: can not allocate play data buffer memory (%d bytes)\n", korg1212->DataBufsSize); - snd_korg1212_free(korg1212); - return -ENOMEM; - } - korg1212->playDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_play.area; - korg1212->PlayDataPhy = korg1212->dma_play.addr; + korg1212->playDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_play->area; + korg1212->PlayDataPhy = korg1212->dma_play->addr; K1212_DEBUG_PRINTK("K1212_DEBUG: Play Data Area = 0x%p (0x%08x), %d bytes\n", korg1212->playDataBufsPtr, korg1212->PlayDataPhy, korg1212->DataBufsSize); - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, - korg1212->DataBufsSize, &korg1212->dma_rec) < 0) { - snd_printk(KERN_ERR "korg1212: can not allocate record data buffer memory (%d bytes)\n", korg1212->DataBufsSize); - snd_korg1212_free(korg1212); - return -ENOMEM; - } - korg1212->recordDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_rec.area; - korg1212->RecDataPhy = korg1212->dma_rec.addr; + korg1212->dma_rec = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, + korg1212->DataBufsSize); + if (!korg1212->dma_rec) + return -ENOMEM; + + korg1212->recordDataBufsPtr = (struct KorgAudioBuffer *)korg1212->dma_rec->area; + korg1212->RecDataPhy = korg1212->dma_rec->addr; K1212_DEBUG_PRINTK("K1212_DEBUG: Record Data Area = 0x%p (0x%08x), %d bytes\n", korg1212->recordDataBufsPtr, korg1212->RecDataPhy, korg1212->DataBufsSize); @@ -2336,26 +2256,22 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, korg1212->AdatTimeCodePhy = korg1212->sharedBufferPhy + offsetof(struct KorgSharedBuffer, AdatTimeCode); + korg1212->dma_dsp = snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, + dsp_code->size); + if (!korg1212->dma_dsp) + return -ENOMEM; + err = request_firmware(&dsp_code, "korg/k1212.dsp", &pci->dev); if (err < 0) { snd_printk(KERN_ERR "firmware not available\n"); - snd_korg1212_free(korg1212); return err; } - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, - dsp_code->size, &korg1212->dma_dsp) < 0) { - snd_printk(KERN_ERR "korg1212: cannot allocate dsp code memory (%zd bytes)\n", dsp_code->size); - snd_korg1212_free(korg1212); - release_firmware(dsp_code); - return -ENOMEM; - } - K1212_DEBUG_PRINTK("K1212_DEBUG: DSP Code area = 0x%p (0x%08x) %d bytes [%s]\n", - korg1212->dma_dsp.area, korg1212->dma_dsp.addr, dsp_code->size, + korg1212->dma_dsp->area, korg1212->dma_dsp->addr, dsp_code->size, stateName[korg1212->cardState]); - memcpy(korg1212->dma_dsp.area, dsp_code->data, dsp_code->size); + memcpy(korg1212->dma_dsp->area, dsp_code->data, dsp_code->size); release_firmware(dsp_code); @@ -2364,12 +2280,6 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, if (rc) K1212_DEBUG_PRINTK("K1212_DEBUG: Reboot Card - RC = %d [%s]\n", rc, stateName[korg1212->cardState]); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, korg1212, &ops); - if (err < 0) { - snd_korg1212_free(korg1212); - return err; - } - snd_korg1212_EnableCardInterrupts(korg1212); mdelay(CARD_BOOT_DELAY_IN_MS); @@ -2411,10 +2321,8 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci, } snd_korg1212_proc_init(korg1212); - - * rchip = korg1212; - return 0; + return 0; } /* @@ -2437,16 +2345,15 @@ snd_korg1212_probe(struct pci_dev *pci, dev++; 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(*korg1212), &card); if (err < 0) return err; + korg1212 = card->private_data; - err = snd_korg1212_create(card, pci, &korg1212); - if (err < 0) { - snd_card_free(card); + err = snd_korg1212_create(card, pci); + if (err < 0) return err; - } strcpy(card->driver, "korg1212"); strcpy(card->shortname, "korg1212"); @@ -2456,25 +2363,17 @@ snd_korg1212_probe(struct pci_dev *pci, K1212_DEBUG_PRINTK("K1212_DEBUG: %s\n", card->longname); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_korg1212_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver korg1212_driver = { .name = KBUILD_MODNAME, .id_table = snd_korg1212_ids, .probe = snd_korg1212_probe, - .remove = snd_korg1212_remove, }; module_pci_driver(korg1212_driver); From patchwork Tue Jul 13 14:28:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474718 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=-18.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, USER_AGENT_GIT 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 2F9D8C07E95 for ; Tue, 13 Jul 2021 14:45:21 +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 4A12760E0B for ; Tue, 13 Jul 2021 14:45:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A12760E0B 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 CB4A31706; Tue, 13 Jul 2021 16:44:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CB4A31706 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187518; bh=XSFCpWcarI/UhCKK6/mXpzQb2gxAtZeW+imCNhjyJEI=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OnXgEr70j3Acrsr1VavcdmPjAEiwyGfaIZriIFKslQKIS+Z6dYOgogpL2n60Jonol Qw7oxkLmuqOnBeck6IGDwaH9BQmsYLjlPCyuidNp/az9FwDxd2R4b89NXfzfDTdgyz HYgeqEMptyfUD7cRlk0q9kzkiKQXa8BqPwQvGf/k= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C87DDF80616; Tue, 13 Jul 2021 16:30:52 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 83440F8052D; Tue, 13 Jul 2021 16:30:06 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 23B4CF8053C for ; Tue, 13 Jul 2021 16:29:41 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 23B4CF8053C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="LYvsuUfY"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="am7jT/Iz" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id DFDE222855 for ; Tue, 13 Jul 2021 14:29:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186580; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FAMtIW8bRBSWt+2TSKRdiNb5VV+3csQJNzMKaqR7Heg=; b=LYvsuUfYClqEQLkHFhz4aoTC+ZZUbb+2XJCN98dDy/+g9eSg50yTlCVIkkx9zq7tvVSkHR oY6Ka8J3e97kN3IXABndVkEvgqoXLSIpnZmOyhmHoUY87q9UiNW9ePsHiyhHesu/s+CDyb pNEVhtuX1NUI+KrVavq1y8iwx2DP5CA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186580; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FAMtIW8bRBSWt+2TSKRdiNb5VV+3csQJNzMKaqR7Heg=; b=am7jT/Izg+bVIGjYbL5x4hZqAgwqAnP5uQiFiOLfcMOMakXD6uzzqAaEP9JmolftBx716l 3AhZTDiyKQ6BLkDg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id D02D5A3B92; Tue, 13 Jul 2021 14:29:40 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 41/51] ALSA: hdspm: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:47 +0200 Message-Id: <20210713142857.19654-42-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI hdspm 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/rme9652/hdspm.c | 64 ++++++++------------------------------- 1 file changed, 12 insertions(+), 52 deletions(-) diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 97a0bff96b28..ff06ee82607c 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c @@ -6575,34 +6575,25 @@ static int snd_hdspm_create(struct snd_card *card, } } - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; pci_set_master(hdspm->pci); - err = pci_request_regions(pci, "hdspm"); + err = pcim_iomap_regions(pci, 1 << 0, "hdspm"); if (err < 0) return err; hdspm->port = pci_resource_start(pci, 0); io_extent = pci_resource_len(pci, 0); - - dev_dbg(card->dev, "grabbed memory region 0x%lx-0x%lx\n", - hdspm->port, hdspm->port + io_extent - 1); - - hdspm->iobase = ioremap(hdspm->port, io_extent); - if (!hdspm->iobase) { - dev_err(card->dev, "unable to remap region 0x%lx-0x%lx\n", - hdspm->port, hdspm->port + io_extent - 1); - return -EBUSY; - } + hdspm->iobase = pcim_iomap_table(pci)[0]; dev_dbg(card->dev, "remapped region (0x%lx) 0x%lx-0x%lx\n", (unsigned long)hdspm->iobase, hdspm->port, hdspm->port + io_extent - 1); - if (request_irq(pci->irq, snd_hdspm_interrupt, - IRQF_SHARED, KBUILD_MODNAME, hdspm)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_hdspm_interrupt, + IRQF_SHARED, KBUILD_MODNAME, hdspm)) { dev_err(card->dev, "unable to use IRQ %d\n", pci->irq); return -EBUSY; } @@ -6614,7 +6605,7 @@ static int snd_hdspm_create(struct snd_card *card, dev_dbg(card->dev, "kmalloc Mixer memory of %zd Bytes\n", sizeof(*hdspm->mixer)); - hdspm->mixer = kzalloc(sizeof(*hdspm->mixer), GFP_KERNEL); + hdspm->mixer = devm_kzalloc(&pci->dev, sizeof(*hdspm->mixer), GFP_KERNEL); if (!hdspm->mixer) return -ENOMEM; @@ -6859,8 +6850,9 @@ static int snd_hdspm_create(struct snd_card *card, } -static int snd_hdspm_free(struct hdspm * hdspm) +static void snd_hdspm_card_free(struct snd_card *card) { + struct hdspm *hdspm = card->private_data; if (hdspm->port) { cancel_work_sync(&hdspm->midi_work); @@ -6873,28 +6865,6 @@ static int snd_hdspm_free(struct hdspm * hdspm) hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); } - - if (hdspm->irq >= 0) - free_irq(hdspm->irq, (void *) hdspm); - - kfree(hdspm->mixer); - iounmap(hdspm->iobase); - - if (hdspm->port) - pci_release_regions(hdspm->pci); - - if (pci_is_enabled(hdspm->pci)) - pci_disable_device(hdspm->pci); - return 0; -} - - -static void snd_hdspm_card_free(struct snd_card *card) -{ - struct hdspm *hdspm = card->private_data; - - if (hdspm) - snd_hdspm_free(hdspm); } @@ -6913,8 +6883,8 @@ static int snd_hdspm_probe(struct pci_dev *pci, return -ENOENT; } - err = snd_card_new(&pci->dev, index[dev], id[dev], - THIS_MODULE, sizeof(*hdspm), &card); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], + THIS_MODULE, sizeof(*hdspm), &card); if (err < 0) return err; @@ -6925,7 +6895,7 @@ static int snd_hdspm_probe(struct pci_dev *pci, err = snd_hdspm_create(card, hdspm); if (err < 0) - goto free_card; + return err; if (hdspm->io_type != MADIface) { snprintf(card->shortname, sizeof(card->shortname), "%s_%x", @@ -6944,28 +6914,18 @@ static int snd_hdspm_probe(struct pci_dev *pci, err = snd_card_register(card); if (err < 0) - goto free_card; + return err; pci_set_drvdata(pci, card); dev++; return 0; - -free_card: - snd_card_free(card); - return err; -} - -static void snd_hdspm_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); } static struct pci_driver hdspm_driver = { .name = KBUILD_MODNAME, .id_table = snd_hdspm_ids, .probe = snd_hdspm_probe, - .remove = snd_hdspm_remove, }; module_pci_driver(hdspm_driver); From patchwork Tue Jul 13 14:28:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474717 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=-18.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, USER_AGENT_GIT 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 19B7AC07E95 for ; Tue, 13 Jul 2021 14:46:00 +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 8FC4D61289 for ; Tue, 13 Jul 2021 14:45:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FC4D61289 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 2C2A7175E; Tue, 13 Jul 2021 16:45:08 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 2C2A7175E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187558; bh=iNq3QaOXfXe8grDWrHSjRyWtauNqVs0q+n2LgMVLFg8=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=jtoZ2ZAQi2wUbPcG+ZDM05hV+79hicGXtlZhbXs80eu++JvrnGL6OS9VAQDwNUezy 9m3vl99zPxg133z1VeYgeXTt0Erk7AwKWU/XChN1teRIxdCv7x7TEN6THD3ezI6EPl 22XrqcKrgKFQO4OqET1z3rn4/Nf9/t2nd3Vnzrz0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id E6445F8061E; Tue, 13 Jul 2021 16:30:53 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D9336F8052E; Tue, 13 Jul 2021 16:30:07 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 93071F80542 for ; Tue, 13 Jul 2021 16:29:41 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 93071F80542 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Kx560Zhg"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="G73ZVZKv" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 701CE22890 for ; Tue, 13 Jul 2021 14:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186581; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5FynoyZ6DnBFWpRSnQMvg3Zq5acyq38aZwxwrcjUPWU=; b=Kx560ZhgT6TT38kzUyoWQRlHtgwJqe9TAN3zycuKzGXkCdtzvBoukmBkN9yuXlF4l6AApa n1OQbDK4XQWuM/4e5zPvw9W1bsn0PfMrjApXcMN9u93hd5tZwCXLi1Ry4FM0uJZNcMlPnH CqARWGL7lkml5LsAK7FPuk4SsNOKq7I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186581; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5FynoyZ6DnBFWpRSnQMvg3Zq5acyq38aZwxwrcjUPWU=; b=G73ZVZKviqNgVqpHyy6t5todeU2+OKb5+Rg7GvMZnV8lPvB8YS9iHOkSvkcol78cEV7YNf HQIP7s4pc2twRQDg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 5F231A3B8E; Tue, 13 Jul 2021 14:29:41 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 42/51] ALSA: rme9652: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:48 +0200 Message-Id: <20210713142857.19654-43-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI rme9652 driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper, the page allocations are done with the 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/rme9652/rme9652.c | 85 +++++++++++-------------------------- 1 file changed, 24 insertions(+), 61 deletions(-) diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c index f1aad38760d6..45448a97070c 100644 --- a/sound/pci/rme9652/rme9652.c +++ b/sound/pci/rme9652/rme9652.c @@ -208,8 +208,8 @@ struct snd_rme9652 { unsigned char ds_channels; unsigned char ss_channels; /* different for hammerfall/hammerfall-light */ - struct snd_dma_buffer playback_dma_buf; - struct snd_dma_buffer capture_dma_buf; + struct snd_dma_buffer *playback_dma_buf; + struct snd_dma_buffer *capture_dma_buf; unsigned char *capture_buffer; /* suitably aligned address */ unsigned char *playback_buffer; /* suitably aligned address */ @@ -275,18 +275,12 @@ static const char channel_map_9636_ds[26] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; -static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size) +static struct snd_dma_buffer * +snd_hammerfall_get_buffer(struct pci_dev *pci, size_t size) { - return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, size, dmab); + return snd_devm_alloc_pages(&pci->dev, SNDRV_DMA_TYPE_DEV, size); } -static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci) -{ - if (dmab->area) - snd_dma_free_pages(dmab); -} - - static const struct pci_device_id snd_rme9652_ids[] = { { .vendor = 0x10ee, @@ -1715,37 +1709,23 @@ static void snd_rme9652_proc_init(struct snd_rme9652 *rme9652) snd_rme9652_proc_read); } -static void snd_rme9652_free_buffers(struct snd_rme9652 *rme9652) +static void snd_rme9652_card_free(struct snd_card *card) { - snd_hammerfall_free_buffer(&rme9652->capture_dma_buf, rme9652->pci); - snd_hammerfall_free_buffer(&rme9652->playback_dma_buf, rme9652->pci); -} + struct snd_rme9652 *rme9652 = (struct snd_rme9652 *) card->private_data; -static int snd_rme9652_free(struct snd_rme9652 *rme9652) -{ if (rme9652->irq >= 0) rme9652_stop(rme9652); - snd_rme9652_free_buffers(rme9652); - - if (rme9652->irq >= 0) - free_irq(rme9652->irq, (void *)rme9652); - iounmap(rme9652->iobase); - if (rme9652->port) - pci_release_regions(rme9652->pci); - - if (pci_is_enabled(rme9652->pci)) - pci_disable_device(rme9652->pci); - return 0; } static int snd_rme9652_initialize_memory(struct snd_rme9652 *rme9652) { unsigned long pb_bus, cb_bus; - if (snd_hammerfall_get_buffer(rme9652->pci, &rme9652->capture_dma_buf, RME9652_DMA_AREA_BYTES) < 0 || - snd_hammerfall_get_buffer(rme9652->pci, &rme9652->playback_dma_buf, RME9652_DMA_AREA_BYTES) < 0) { - if (rme9652->capture_dma_buf.area) - snd_dma_free_pages(&rme9652->capture_dma_buf); + rme9652->capture_dma_buf = + snd_hammerfall_get_buffer(rme9652->pci, RME9652_DMA_AREA_BYTES); + rme9652->playback_dma_buf = + snd_hammerfall_get_buffer(rme9652->pci, RME9652_DMA_AREA_BYTES); + if (!rme9652->capture_dma_buf || !rme9652->playback_dma_buf) { dev_err(rme9652->card->dev, "%s: no buffers available\n", rme9652->card_name); return -ENOMEM; @@ -1753,16 +1733,16 @@ static int snd_rme9652_initialize_memory(struct snd_rme9652 *rme9652) /* Align to bus-space 64K boundary */ - cb_bus = ALIGN(rme9652->capture_dma_buf.addr, 0x10000ul); - pb_bus = ALIGN(rme9652->playback_dma_buf.addr, 0x10000ul); + cb_bus = ALIGN(rme9652->capture_dma_buf->addr, 0x10000ul); + pb_bus = ALIGN(rme9652->playback_dma_buf->addr, 0x10000ul); /* Tell the card where it is */ rme9652_write(rme9652, RME9652_rec_buffer, cb_bus); rme9652_write(rme9652, RME9652_play_buffer, pb_bus); - rme9652->capture_buffer = rme9652->capture_dma_buf.area + (cb_bus - rme9652->capture_dma_buf.addr); - rme9652->playback_buffer = rme9652->playback_dma_buf.area + (pb_bus - rme9652->playback_dma_buf.addr); + rme9652->capture_buffer = rme9652->capture_dma_buf->area + (cb_bus - rme9652->capture_dma_buf->addr); + rme9652->playback_buffer = rme9652->playback_dma_buf->area + (pb_bus - rme9652->playback_dma_buf->addr); return 0; } @@ -2452,7 +2432,7 @@ static int snd_rme9652_create(struct snd_card *card, return -ENODEV; } - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; @@ -2462,15 +2442,15 @@ static int snd_rme9652_create(struct snd_card *card, if (err < 0) return err; rme9652->port = pci_resource_start(pci, 0); - rme9652->iobase = ioremap(rme9652->port, RME9652_IO_EXTENT); + rme9652->iobase = devm_ioremap(&pci->dev, rme9652->port, RME9652_IO_EXTENT); if (rme9652->iobase == NULL) { dev_err(card->dev, "unable to remap region 0x%lx-0x%lx\n", rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1); return -EBUSY; } - if (request_irq(pci->irq, snd_rme9652_interrupt, IRQF_SHARED, - KBUILD_MODNAME, rme9652)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_rme9652_interrupt, + IRQF_SHARED, KBUILD_MODNAME, rme9652)) { dev_err(card->dev, "unable to request IRQ %d\n", pci->irq); return -EBUSY; } @@ -2562,14 +2542,6 @@ static int snd_rme9652_create(struct snd_card *card, return 0; } -static void snd_rme9652_card_free(struct snd_card *card) -{ - struct snd_rme9652 *rme9652 = (struct snd_rme9652 *) card->private_data; - - if (rme9652) - snd_rme9652_free(rme9652); -} - static int snd_rme9652_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { @@ -2585,8 +2557,8 @@ static int snd_rme9652_probe(struct pci_dev *pci, return -ENOENT; } - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, - sizeof(struct snd_rme9652), &card); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, + sizeof(struct snd_rme9652), &card); if (err < 0) return err; @@ -2597,33 +2569,24 @@ static int snd_rme9652_probe(struct pci_dev *pci, rme9652->pci = pci; err = snd_rme9652_create(card, rme9652, precise_ptr[dev]); if (err) - goto free_card; + return err; strcpy(card->shortname, rme9652->card_name); sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname, rme9652->port, rme9652->irq); err = snd_card_register(card); - if (err) { -free_card: - snd_card_free(card); + if (err) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_rme9652_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver rme9652_driver = { .name = KBUILD_MODNAME, .id_table = snd_rme9652_ids, .probe = snd_rme9652_probe, - .remove = snd_rme9652_remove, }; module_pci_driver(rme9652_driver); From patchwork Tue Jul 13 14:28:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474714 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=-18.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, USER_AGENT_GIT 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 522FAC07E95 for ; Tue, 13 Jul 2021 14:48:07 +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 C3B736128B for ; Tue, 13 Jul 2021 14:48:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C3B736128B 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 6208E170F; Tue, 13 Jul 2021 16:47:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6208E170F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187685; bh=m6ILTGs7GK2tsm14WjfjsUSsqSUzELYYb8MomHLz2UY=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=GkaIU0e0e0tMP0pCikor2ZZQaqKUepsxkzxvVC2hq7Iydb1bHsKMjqI2vul4YkFtQ HJO8Du8rsZ3ugHDzIGAuGDOZxhHmF1XKOENN0uuAXmN0xLKIgEAbT2ztQusmxGUuSF jDPL9Qzw63OD1nqg5nyeuc7qscCj5pAXbLEcsSGw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 1D1BEF8063B; Tue, 13 Jul 2021 16:31:06 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1B008F804E5; Tue, 13 Jul 2021 16:30:13 +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 2BDEEF80544 for ; Tue, 13 Jul 2021 16:29:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 2BDEEF80544 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Ai1heuHn"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Y4NHK4b0" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 04807201DA for ; Tue, 13 Jul 2021 14:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5eZyHW0wparX5iqE8KWGZU+8cEcEGbfEFwNVc/IO0SY=; b=Ai1heuHnC08t0G9F7bTuOKuNyTDX/zMXweycK3/MxXeqSPy/jmg+nM8ww7BsRF1fkn1S5W b8aqgDfOKUVH1z5oP1tZiRCrFjsJsrFxqmdxk1wvyxx1J5sxgfiUsBWvd0n2lwSxz7Ysw3 Od1m9KDzSMzSn0t5LKFQIO6aehain0g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5eZyHW0wparX5iqE8KWGZU+8cEcEGbfEFwNVc/IO0SY=; b=Y4NHK4b01okooDmehtXUk5RyBhw+a6uMwMX1SuDHFpkdPl9Nl57buxTzALek0osinin20G VrK3RJt/cAhE5TCQ== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id E5FD3A3B8E; Tue, 13 Jul 2021 14:29:41 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 43/51] ALSA: trident: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:49 +0200 Message-Id: <20210713142857.19654-44-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in PCI trident driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper, the page allocations are done with the 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/trident/trident.c | 39 ++++--------- sound/pci/trident/trident.h | 7 +-- sound/pci/trident/trident_main.c | 90 +++++++++--------------------- sound/pci/trident/trident_memory.c | 8 +-- 4 files changed, 44 insertions(+), 100 deletions(-) diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c index 60e4dca28c2b..9922ab40798c 100644 --- a/sound/pci/trident/trident.c +++ b/sound/pci/trident/trident.c @@ -62,21 +62,18 @@ static int snd_trident_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(*trident), &card); if (err < 0) return err; + trident = card->private_data; err = snd_trident_create(card, pci, pcm_channels[dev], ((pci->vendor << 16) | pci->device) == TRIDENT_DEVICE_ID_SI7018 ? 1 : 2, - wavetable_size[dev], - &trident); - if (err < 0) { - snd_card_free(card); + wavetable_size[dev]); + if (err < 0) return err; - } - card->private_data = trident; switch (trident->device) { case TRIDENT_DEVICE_ID_DX: @@ -102,26 +99,20 @@ static int snd_trident_probe(struct pci_dev *pci, card->shortname, trident->port, trident->irq); err = snd_trident_pcm(trident, pcm_dev++); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } switch (trident->device) { case TRIDENT_DEVICE_ID_DX: case TRIDENT_DEVICE_ID_NX: err = snd_trident_foldback_pcm(trident, pcm_dev++); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } break; } if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) { err = snd_trident_spdif_pcm(trident, pcm_dev++); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } } if (trident->device != TRIDENT_DEVICE_ID_SI7018) { err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, @@ -129,34 +120,24 @@ static int snd_trident_probe(struct pci_dev *pci, MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, -1, &trident->rmidi); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } } snd_trident_create_gameport(trident); err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pci_set_drvdata(pci, card); dev++; return 0; } -static void snd_trident_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); -} - static struct pci_driver trident_driver = { .name = KBUILD_MODNAME, .id_table = snd_trident_ids, .probe = snd_trident_probe, - .remove = snd_trident_remove, #ifdef CONFIG_PM_SLEEP .driver = { .pm = &snd_trident_pm, diff --git a/sound/pci/trident/trident.h b/sound/pci/trident/trident.h index c579a44bb9ae..9768a7fc2349 100644 --- a/sound/pci/trident/trident.h +++ b/sound/pci/trident/trident.h @@ -251,9 +251,9 @@ struct snd_trident_memblk_arg { struct snd_trident_tlb { __le32 *entries; /* 16k-aligned TLB table */ dma_addr_t entries_dmaaddr; /* 16k-aligned PCI address to TLB table */ - struct snd_dma_buffer buffer; + struct snd_dma_buffer *buffer; struct snd_util_memhdr * memhdr; /* page allocation list */ - struct snd_dma_buffer silent_page; + struct snd_dma_buffer *silent_page; }; struct snd_trident_voice { @@ -400,8 +400,7 @@ int snd_trident_create(struct snd_card *card, struct pci_dev *pci, int pcm_streams, int pcm_spdif_device, - int max_wavetable_size, - struct snd_trident ** rtrident); + int max_wavetable_size); int snd_trident_create_gameport(struct snd_trident *trident); int snd_trident_pcm(struct snd_trident *trident, int device); diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c index cfbca3bd60ed..e98eea1e6d81 100644 --- a/sound/pci/trident/trident_main.c +++ b/sound/pci/trident/trident_main.c @@ -42,7 +42,7 @@ static int snd_trident_sis_reset(struct snd_trident *trident); static void snd_trident_clear_voices(struct snd_trident * trident, unsigned short v_min, unsigned short v_max); -static int snd_trident_free(struct snd_trident *trident); +static void snd_trident_free(struct snd_card *card); /* * common I/O routines @@ -3299,12 +3299,6 @@ static void snd_trident_proc_init(struct snd_trident *trident) snd_card_ro_proc_new(trident->card, s, trident, snd_trident_proc_read); } -static int snd_trident_dev_free(struct snd_device *device) -{ - struct snd_trident *trident = device->device_data; - return snd_trident_free(trident); -} - /*--------------------------------------------------------------------------- snd_trident_tlb_alloc @@ -3324,23 +3318,27 @@ static int snd_trident_tlb_alloc(struct snd_trident *trident) /* TLB array must be aligned to 16kB !!! so we allocate 32kB region and correct offset when necessary */ - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &trident->pci->dev, - 2 * SNDRV_TRIDENT_MAX_PAGES * 4, &trident->tlb.buffer) < 0) { + trident->tlb.buffer = + snd_devm_alloc_pages(&trident->pci->dev, SNDRV_DMA_TYPE_DEV, + 2 * SNDRV_TRIDENT_MAX_PAGES * 4); + if (!trident->tlb.buffer) { dev_err(trident->card->dev, "unable to allocate TLB buffer\n"); return -ENOMEM; } - trident->tlb.entries = (__le32 *)ALIGN((unsigned long)trident->tlb.buffer.area, SNDRV_TRIDENT_MAX_PAGES * 4); - trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer.addr, SNDRV_TRIDENT_MAX_PAGES * 4); + trident->tlb.entries = (__le32 *)ALIGN((unsigned long)trident->tlb.buffer->area, SNDRV_TRIDENT_MAX_PAGES * 4); + trident->tlb.entries_dmaaddr = ALIGN(trident->tlb.buffer->addr, SNDRV_TRIDENT_MAX_PAGES * 4); /* allocate and setup silent page and initialise TLB entries */ - if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &trident->pci->dev, - SNDRV_TRIDENT_PAGE_SIZE, &trident->tlb.silent_page) < 0) { + trident->tlb.silent_page = + snd_devm_alloc_pages(&trident->pci->dev, SNDRV_DMA_TYPE_DEV, + SNDRV_TRIDENT_PAGE_SIZE); + if (!trident->tlb.silent_page) { dev_err(trident->card->dev, "unable to allocate silent page\n"); return -ENOMEM; } - memset(trident->tlb.silent_page.area, 0, SNDRV_TRIDENT_PAGE_SIZE); + memset(trident->tlb.silent_page->area, 0, SNDRV_TRIDENT_PAGE_SIZE); for (i = 0; i < SNDRV_TRIDENT_MAX_PAGES; i++) - trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page.addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1)); + trident->tlb.entries[i] = cpu_to_le32(trident->tlb.silent_page->addr & ~(SNDRV_TRIDENT_PAGE_SIZE-1)); /* use emu memory block manager code to manage tlb page allocation */ trident->tlb.memhdr = snd_util_memhdr_new(SNDRV_TRIDENT_PAGE_SIZE * SNDRV_TRIDENT_MAX_PAGES); @@ -3497,36 +3495,24 @@ int snd_trident_create(struct snd_card *card, struct pci_dev *pci, int pcm_streams, int pcm_spdif_device, - int max_wavetable_size, - struct snd_trident ** rtrident) + int max_wavetable_size) { - struct snd_trident *trident; + struct snd_trident *trident = card->private_data; int i, err; struct snd_trident_voice *voice; struct snd_trident_pcm_mixer *tmix; - static const struct snd_device_ops ops = { - .dev_free = snd_trident_dev_free, - }; - - *rtrident = NULL; /* enable PCI device */ - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; /* check, if we can restrict PCI DMA transfers to 30 bits */ if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(30))) { dev_err(card->dev, "architecture does not support 30bit PCI busmaster DMA\n"); - pci_disable_device(pci); return -ENXIO; } - trident = kzalloc(sizeof(*trident), GFP_KERNEL); - if (trident == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } trident->device = (pci->vendor << 16) | pci->device; trident->card = card; trident->pci = pci; @@ -3542,22 +3528,19 @@ int snd_trident_create(struct snd_card *card, max_wavetable_size = 0; trident->synth.max_size = max_wavetable_size * 1024; trident->irq = -1; + card->private_free = snd_trident_free; trident->midi_port = TRID_REG(trident, T4D_MPU401_BASE); pci_set_master(pci); err = pci_request_regions(pci, "Trident Audio"); - if (err < 0) { - kfree(trident); - pci_disable_device(pci); + if (err < 0) return err; - } trident->port = pci_resource_start(pci, 0); - if (request_irq(pci->irq, snd_trident_interrupt, IRQF_SHARED, - KBUILD_MODNAME, trident)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_trident_interrupt, + IRQF_SHARED, KBUILD_MODNAME, trident)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_trident_free(trident); return -EBUSY; } trident->irq = pci->irq; @@ -3565,13 +3548,10 @@ int snd_trident_create(struct snd_card *card, /* allocate 16k-aligned TLB for NX cards */ trident->tlb.entries = NULL; - trident->tlb.buffer.area = NULL; if (trident->device == TRIDENT_DEVICE_ID_NX) { err = snd_trident_tlb_alloc(trident); - if (err < 0) { - snd_trident_free(trident); + if (err < 0) return err; - } } trident->spdif_bits = trident->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF; @@ -3591,16 +3571,8 @@ int snd_trident_create(struct snd_card *card, snd_BUG(); break; } - if (err < 0) { - snd_trident_free(trident); - return err; - } - - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, trident, &ops); - if (err < 0) { - snd_trident_free(trident); + if (err < 0) return err; - } err = snd_trident_mixer(trident, pcm_spdif_device); if (err < 0) @@ -3624,7 +3596,6 @@ int snd_trident_create(struct snd_card *card, snd_trident_enable_eso(trident); snd_trident_proc_init(trident); - *rtrident = trident; return 0; } @@ -3634,14 +3605,16 @@ int snd_trident_create(struct snd_card *card, Description: This routine will free the device specific class for the 4DWave card. - Parameters: trident - device specific private data for 4DWave card + Parameters: card - card to release Returns: None. ---------------------------------------------------------------------------*/ -static int snd_trident_free(struct snd_trident *trident) +static void snd_trident_free(struct snd_card *card) { + struct snd_trident *trident = card->private_data; + snd_trident_free_gameport(trident); snd_trident_disable_eso(trident); // Disable S/PDIF out @@ -3650,19 +3623,10 @@ static int snd_trident_free(struct snd_trident *trident) else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); } - if (trident->irq >= 0) - free_irq(trident->irq, trident); - if (trident->tlb.buffer.area) { + if (trident->tlb.buffer) { outl(0, TRID_REG(trident, NX_TLBC)); snd_util_memhdr_free(trident->tlb.memhdr); - if (trident->tlb.silent_page.area) - snd_dma_free_pages(&trident->tlb.silent_page); - snd_dma_free_pages(&trident->tlb.buffer); } - pci_release_regions(trident->pci); - pci_disable_device(trident->pci); - kfree(trident); - return 0; } /*--------------------------------------------------------------------------- diff --git a/sound/pci/trident/trident_memory.c b/sound/pci/trident/trident_memory.c index 4ad3855101c9..05de2b9f4ed7 100644 --- a/sound/pci/trident/trident_memory.c +++ b/sound/pci/trident/trident_memory.c @@ -31,7 +31,7 @@ /* fill TLB entrie(s) corresponding to page with ptr */ #define set_tlb_bus(trident,page,addr) __set_tlb_bus(trident,page,addr) /* fill TLB entrie(s) corresponding to page with silence pointer */ -#define set_silent_tlb(trident,page) __set_tlb_bus(trident, page, trident->tlb.silent_page.addr) +#define set_silent_tlb(trident,page) __set_tlb_bus(trident, page, trident->tlb.silent_page->addr) /* get aligned page from offset address */ #define get_aligned_page(offset) ((offset) >> 12) /* get offset address from aligned page */ @@ -58,8 +58,8 @@ static inline void set_tlb_bus(struct snd_trident *trident, int page, static inline void set_silent_tlb(struct snd_trident *trident, int page) { page <<= 1; - __set_tlb_bus(trident, page, trident->tlb.silent_page.addr); - __set_tlb_bus(trident, page+1, trident->tlb.silent_page.addr); + __set_tlb_bus(trident, page, trident->tlb.silent_page->addr); + __set_tlb_bus(trident, page+1, trident->tlb.silent_page->addr); } #else @@ -92,7 +92,7 @@ static inline void set_silent_tlb(struct snd_trident *trident, int page) int i; page *= UNIT_PAGES; for (i = 0; i < UNIT_PAGES; i++, page++) - __set_tlb_bus(trident, page, trident->tlb.silent_page.addr); + __set_tlb_bus(trident, page, trident->tlb.silent_page->addr); } #endif /* PAGE_SIZE */ From patchwork Tue Jul 13 14:28:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474716 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=-18.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, USER_AGENT_GIT 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 89885C07E95 for ; Tue, 13 Jul 2021 14:46:41 +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 157B560E0B for ; Tue, 13 Jul 2021 14:46:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 157B560E0B 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 AFFDF174D; Tue, 13 Jul 2021 16:45:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AFFDF174D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187599; bh=1nXVLbJizRCzbqWhJsYwntzhTvFTPeQw0VyNJjq0Xc0=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lM8c2DMWsuK888PyFti3UjamqCeKsAqpjFLB4u/hjp8VMt64Pmqgeohj20MXZEgR3 l+jpv6lMusLPvHzezvS5WqLVKvC4OxoRv9SInUbuCmeIdG3friea6a/M5CgivvExUb FPihjRKv65N22dsQV46dXgB5+rsxsbTcNZnPJYoc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 483EAF80623; Tue, 13 Jul 2021 16:30:55 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C3529F8052D; Tue, 13 Jul 2021 16:30:08 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 A88ADF80551 for ; Tue, 13 Jul 2021 16:29:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A88ADF80551 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="i7WyzWTk"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="hyE9EUJZ" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 82ECB22837 for ; Tue, 13 Jul 2021 14:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eW8LFcUjjkXO6ltupu8MlVuWejyBsrIe+N/GJDppXF0=; b=i7WyzWTkNDy9EWT5e6a/lwJH96WimDfnMLJ4KnQTAN6KxWlPQTV2qtIaEzA0W8KQg/o8s+ hznTKP4MkWm2Eqiac8VvJa87tPK8hcGWHDIHiC+/ywbHZ/3vTU4QhlL/bHn+cDgrbIXsCv jsOoAmEG5dDaeAcxJKbqlZ55+6api8A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186582; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eW8LFcUjjkXO6ltupu8MlVuWejyBsrIe+N/GJDppXF0=; b=hyE9EUJZyOF9q73cShrLi0RilCp7rEKYicaLPB0w4B1AEZWQnIE0lJvOPybxrXqPeXBU1n c4DGrkAfRYX3k4CQ== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 72C4DA3B8E; Tue, 13 Jul 2021 14:29:42 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 44/51] ALSA: vx: Manage vx_core object with devres Date: Tue, 13 Jul 2021 16:28:50 +0200 Message-Id: <20210713142857.19654-45-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" The firmware data are also released automatically. Signed-off-by: Takashi Iwai --- sound/drivers/vx/vx_core.c | 12 ++++++++++-- sound/pci/vx222/vx222.c | 1 - sound/pcmcia/vx/vxpocket.c | 21 --------------------- 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/sound/drivers/vx/vx_core.c b/sound/drivers/vx/vx_core.c index a10449af5a76..18901e5bcfcf 100644 --- a/sound/drivers/vx/vx_core.c +++ b/sound/drivers/vx/vx_core.c @@ -774,6 +774,11 @@ int snd_vx_resume(struct vx_core *chip) EXPORT_SYMBOL(snd_vx_resume); #endif +static void snd_vx_release(struct device *dev, void *data) +{ + snd_vx_free_firmware(data); +} + /** * snd_vx_create - constructor for struct vx_core * @card: card instance @@ -784,6 +789,8 @@ EXPORT_SYMBOL(snd_vx_resume); * this function allocates the instance and prepare for the hardware * initialization. * + * The object is managed via devres, and will be automatically released. + * * return the instance pointer if successful, NULL in error. */ struct vx_core *snd_vx_create(struct snd_card *card, @@ -796,8 +803,9 @@ struct vx_core *snd_vx_create(struct snd_card *card, if (snd_BUG_ON(!card || !hw || !ops)) return NULL; - chip = kzalloc(sizeof(*chip) + extra_size, GFP_KERNEL); - if (! chip) + chip = devres_alloc(snd_vx_release, sizeof(*chip) + extra_size, + GFP_KERNEL); + if (!chip) return NULL; mutex_init(&chip->lock); chip->irq = -1; diff --git a/sound/pci/vx222/vx222.c b/sound/pci/vx222/vx222.c index 04c7204cb7bc..46a80ef1d481 100644 --- a/sound/pci/vx222/vx222.c +++ b/sound/pci/vx222/vx222.c @@ -109,7 +109,6 @@ static int snd_vx222_free(struct vx_core *chip) if (vx->port[0]) pci_release_regions(vx->pci); pci_disable_device(vx->pci); - kfree(chip); return 0; } diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c index 0dfb6a943b60..30ac1f96c6c7 100644 --- a/sound/pcmcia/vx/vxpocket.c +++ b/sound/pcmcia/vx/vxpocket.c @@ -50,19 +50,6 @@ static void vxpocket_release(struct pcmcia_device *link) pcmcia_disable_device(link); } -/* - * destructor, called from snd_card_free_when_closed() - */ -static int snd_vxpocket_dev_free(struct snd_device *device) -{ - struct vx_core *chip = device->device_data; - - snd_vx_free_firmware(chip); - kfree(chip); - return 0; -} - - /* * Hardware information */ @@ -122,9 +109,6 @@ static int snd_vxpocket_new(struct snd_card *card, int ibl, { struct vx_core *chip; struct snd_vxpocket *vxp; - static const struct snd_device_ops ops = { - .dev_free = snd_vxpocket_dev_free, - }; int err; chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops, @@ -132,11 +116,6 @@ static int snd_vxpocket_new(struct snd_card *card, int ibl, if (!chip) return -ENOMEM; - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - kfree(chip); - return err; - } chip->ibl.size = ibl; vxp = to_vxpocket(chip); From patchwork Tue Jul 13 14:28:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474715 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=-18.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, USER_AGENT_GIT 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 82059C07E95 for ; Tue, 13 Jul 2021 14:47:25 +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 0B24461289 for ; Tue, 13 Jul 2021 14:47:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B24461289 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 969081766; Tue, 13 Jul 2021 16:46:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 969081766 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187643; bh=1LgK4r7Nt4cZqkoHSz3NM/gpMmd8SDCt8Uebltn1EFI=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ihHr8F3FyPQpIYugQk1gzX/tctrch+i187Hqu+PcnMqt57H5ftfXU6LUX4yRKnQ+4 3dBjZG9kXt4939uO+GGKHADmyY6uKABHx5ySJ/tmcj5a1dnbWZThmwUM3fvFVYG4Cj FFzdHPIGyRNbuKtf+2AxFPEH8Asqyc9VknwB0ZiE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 69640F80633; Tue, 13 Jul 2021 16:30:56 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 818D5F804F3; Tue, 13 Jul 2021 16:30:11 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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 3212CF8016A for ; Tue, 13 Jul 2021 16:29:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3212CF8016A Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="VGwa4VKN"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="UAym//pK" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 11E6522837 for ; Tue, 13 Jul 2021 14:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186584; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6fmFbwAl0scRniMBGRmt/LYV5Q59V+Yu7zP10IIZFwE=; b=VGwa4VKNidNIvC6TzAWg8jmPTwbDmP27UXP7GTnpdL+YSGzdGnDo1r0IkZUlpkxQnJHrju DchyTG5zo7H4DulOQNTka4z4k7Mg+7a05RfJod/g/NWrmTbThivC0qBpWDavcN1hXsmh8j rJyzbgXORSvzoojwlqBnZwlrS76wHXY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186584; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6fmFbwAl0scRniMBGRmt/LYV5Q59V+Yu7zP10IIZFwE=; b=UAym//pKU0DHoUymrZIxKcUjluB9CHZVtdjGpsjS3iCVBeJxoUN1PnxG3uT/nFRlMcLcyP RjCyrJQKQA6HwMBQ== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 015E0A3B92; Tue, 13 Jul 2021 14:29:44 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 47/51] ALSA: x86: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:53 +0200 Message-Id: <20210713142857.19654-48-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the resource management in x86 HDMI LPE audio driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper now. Signed-off-by: Takashi Iwai --- sound/x86/intel_hdmi_audio.c | 57 ++++++++++-------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/sound/x86/intel_hdmi_audio.c b/sound/x86/intel_hdmi_audio.c index 6d87c099d997..d60e532edf5f 100644 --- a/sound/x86/intel_hdmi_audio.c +++ b/sound/x86/intel_hdmi_audio.c @@ -1657,11 +1657,6 @@ static void hdmi_lpe_audio_free(struct snd_card *card) cancel_work_sync(&ctx->hdmi_audio_wq); } - - if (card_ctx->mmio_start) - iounmap(card_ctx->mmio_start); - if (card_ctx->irq >= 0) - free_irq(card_ctx->irq, card_ctx); } /* @@ -1699,8 +1694,8 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev) } /* create a card instance with ALSA framework */ - ret = snd_card_new(&pdev->dev, hdmi_card_index, hdmi_card_id, - THIS_MODULE, sizeof(*card_ctx), &card); + ret = snd_devm_card_new(&pdev->dev, hdmi_card_index, hdmi_card_id, + THIS_MODULE, sizeof(*card_ctx), &card); if (ret) return ret; @@ -1736,20 +1731,20 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev) __func__, (unsigned int)res_mmio->start, (unsigned int)res_mmio->end); - card_ctx->mmio_start = ioremap(res_mmio->start, - (size_t)(resource_size(res_mmio))); + card_ctx->mmio_start = + devm_ioremap(&pdev->dev, res_mmio->start, + (size_t)(resource_size(res_mmio))); if (!card_ctx->mmio_start) { dev_err(&pdev->dev, "Could not get ioremap\n"); - ret = -EACCES; - goto err; + return -EACCES; } /* setup interrupt handler */ - ret = request_irq(irq, display_pipe_interrupt_handler, 0, - pdev->name, card_ctx); + ret = devm_request_irq(&pdev->dev, irq, display_pipe_interrupt_handler, + 0, pdev->name, card_ctx); if (ret < 0) { dev_err(&pdev->dev, "request_irq failed\n"); - goto err; + return ret; } card_ctx->irq = irq; @@ -1769,7 +1764,7 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev) ret = snd_pcm_new(card, INTEL_HAD, port, MAX_PB_STREAMS, MAX_CAP_STREAMS, &pcm); if (ret) - goto err; + return ret; /* setup private data which can be retrieved when required */ pcm->private_data = ctx; @@ -1790,31 +1785,29 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev) struct snd_kcontrol *kctl; kctl = snd_ctl_new1(&had_controls[i], ctx); - if (!kctl) { - ret = -ENOMEM; - goto err; - } + if (!kctl) + return -ENOMEM; kctl->id.device = pcm->device; ret = snd_ctl_add(card, kctl); if (ret < 0) - goto err; + return ret; } /* Register channel map controls */ ret = had_register_chmap_ctls(ctx, pcm); if (ret < 0) - goto err; + return ret; ret = had_create_jack(ctx, pcm); if (ret < 0) - goto err; + return ret; } ret = snd_card_register(card); if (ret) - goto err; + return ret; spin_lock_irq(&pdata->lpe_audio_slock); pdata->notify_audio_lpe = notify_audio_lpe; @@ -1831,23 +1824,6 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev) } return 0; - -err: - snd_card_free(card); - return ret; -} - -/* - * hdmi_lpe_audio_remove - stop bridge with i915 - * - * This function is called when the platform device is destroyed. - */ -static int hdmi_lpe_audio_remove(struct platform_device *pdev) -{ - struct snd_intelhad_card *card_ctx = platform_get_drvdata(pdev); - - snd_card_free(card_ctx->card); - return 0; } static const struct dev_pm_ops hdmi_lpe_audio_pm = { @@ -1860,7 +1836,6 @@ static struct platform_driver hdmi_lpe_audio_driver = { .pm = &hdmi_lpe_audio_pm, }, .probe = hdmi_lpe_audio_probe, - .remove = hdmi_lpe_audio_remove, }; module_platform_driver(hdmi_lpe_audio_driver); From patchwork Tue Jul 13 14:28:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474712 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=-18.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, USER_AGENT_GIT 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 B3157C07E95 for ; Tue, 13 Jul 2021 14:49:32 +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 306EE610CB for ; Tue, 13 Jul 2021 14:49:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 306EE610CB 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 C408B1775; Tue, 13 Jul 2021 16:48:40 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C408B1775 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187770; bh=BcouPs2oiOXfISqCuhU9v3hJt1yTHbZsJ/KJv8DjMYQ=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=TX4lJaKvJJt++jRI4M0ZpgJTiLg6RHPpGEv3rWxuVJV7sTA5c+Ot80tF/yVcp77t6 Gh/gXRDx98ZDs8oF451PngfirXBsFwJVFF7JxeXaPmURjVkrIb8Bte24s1PMxfEOYB A01DA2FSCoGqsj3yy0piNNTsqxdzH3c/KtwoHuPQ= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3BDE0F80674; Tue, 13 Jul 2021 16:31:10 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 12419F805AA; Tue, 13 Jul 2021 16:30:21 +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 C5351F80520 for ; Tue, 13 Jul 2021 16:29:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz C5351F80520 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="0AIwgpnS"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="FU+WUh3t" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 9B44C201DA for ; Tue, 13 Jul 2021 14:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186584; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WBwQBJBGsn4PeR2I3zEBE2ni2A8jQnZMXEn2wo06JxI=; b=0AIwgpnSXh4uvx6ZWpo/vYA4o4xsO2wgGE9nDg8u7AnVou1zqKQDJ4P4mNGKKrpQylRFc3 ptA3aF2kVpSQRQPNcXVgW5iegZbgPHsX58/UL53Q11RIsu1ASTxHwZYwDgmW2C3Gzmzpc9 vBPBZ+MuhK+Y38NDh60MBohRLJSmzlM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186584; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WBwQBJBGsn4PeR2I3zEBE2ni2A8jQnZMXEn2wo06JxI=; b=FU+WUh3tpxJ1EUBeNH95ypsLFlE+QcTfMYUH1WA3PoDAyBzwiYxKaZ51OYZUtvzAaDR5bT iNPZi3x0A+kyRrAg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 88A63A3B92; Tue, 13 Jul 2021 14:29:44 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 48/51] ALSA: virmidi: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:54 +0200 Message-Id: <20210713142857.19654-49-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the card object management with devres as a clean up. The remove callback gets reduced by that. This should give no user-visible functional changes. Signed-off-by: Takashi Iwai --- sound/drivers/virmidi.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c index 4206d93ab47e..7f7eed6faaae 100644 --- a/sound/drivers/virmidi.c +++ b/sound/drivers/virmidi.c @@ -75,8 +75,8 @@ static int snd_virmidi_probe(struct platform_device *devptr) int idx, err; int dev = devptr->id; - err = snd_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, - sizeof(struct snd_card_virmidi), &card); + err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, + sizeof(struct snd_card_virmidi), &card); if (err < 0) return err; vmidi = card->private_data; @@ -94,7 +94,7 @@ static int snd_virmidi_probe(struct platform_device *devptr) err = snd_virmidi_new(card, idx, &rmidi); if (err < 0) - goto __nodev; + return err; rdev = rmidi->private_data; vmidi->midi[idx] = rmidi; strcpy(rmidi->name, "Virtual Raw MIDI"); @@ -106,18 +106,10 @@ static int snd_virmidi_probe(struct platform_device *devptr) sprintf(card->longname, "Virtual MIDI Card %i", dev + 1); err = snd_card_register(card); - if (!err) { - platform_set_drvdata(devptr, card); - return 0; - } -__nodev: - snd_card_free(card); - return err; -} + if (err) + return err; -static int snd_virmidi_remove(struct platform_device *devptr) -{ - snd_card_free(platform_get_drvdata(devptr)); + platform_set_drvdata(devptr, card); return 0; } @@ -125,7 +117,6 @@ static int snd_virmidi_remove(struct platform_device *devptr) static struct platform_driver snd_virmidi_driver = { .probe = snd_virmidi_probe, - .remove = snd_virmidi_remove, .driver = { .name = SND_VIRMIDI_DRIVER, }, From patchwork Tue Jul 13 14:28:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 474713 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=-18.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, USER_AGENT_GIT 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 D2ED6C07E95 for ; Tue, 13 Jul 2021 14:48:50 +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 50237611AB for ; Tue, 13 Jul 2021 14:48:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50237611AB 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 DEE29176A; Tue, 13 Jul 2021 16:47:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz DEE29176A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1626187729; bh=K6SYEnn0Tqwq/fjv+dY0b42AyzcgoOn2IYhhMSZuyDs=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=uf0iyQkq4Ed9AiLbqCHvgelSYIHJwNgeHwKZDCBLO07U8yJ4m68cekXG0+USA82Fw 9D96NAhp9h30anzdS1Zth262IsolVhCq4d6tmRZe3eTcHUkOPK6W12OQDXVcdyNX24 KVeS8FJ2s4qGwsOcbsPkhxW6lPnvj+BRmal1rO+s= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C731AF80659; Tue, 13 Jul 2021 16:31:07 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8CD24F805AA; Tue, 13 Jul 2021 16:30:18 +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 7F4E7F804FC for ; Tue, 13 Jul 2021 16:29:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7F4E7F804FC Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Z8c5UsqD"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="D+G6Ou3H" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 4FBAE201DA for ; Tue, 13 Jul 2021 14:29:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1626186586; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m6xVTqFDQohmoxIEf9s0z5yYHkj3CpZtaIStWQHEs2I=; b=Z8c5UsqDxJhI+XREw34BLPnDG5s5MJxyEyMTa4k3DEejHhpPE1wTT5ynL7p7fvrruQeGwP l5uiQrilEiA1AhIvEtWW7SJmjqZ+Mu6r05cYSTGtNRHx9IaLRjGYwJ4vyZu1ufU2JhXQQH CYiIYbV2+15oefp2TdKnBIPGVzCvbBE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1626186586; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m6xVTqFDQohmoxIEf9s0z5yYHkj3CpZtaIStWQHEs2I=; b=D+G6Ou3HrpKWocngJjebvn9rvitqCqLuOy231MVJftIlVyERP1OaJF2yzCLYQg0RMRzkMR qE38LHpBBSEN9lCA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 40070A3B8C; Tue, 13 Jul 2021 14:29:46 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH 51/51] ALSA: mpu401: Allocate resources with device-managed APIs Date: Tue, 13 Jul 2021 16:28:57 +0200 Message-Id: <20210713142857.19654-52-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210713142857.19654-1-tiwai@suse.de> References: <20210713142857.19654-1-tiwai@suse.de> MIME-Version: 1.0 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" This patch converts the card object management with devres as a clean up. The remove callback gets reduced by that. This should give no user-visible functional changes. Note that this converts only the mpu401 card driver. The mpu401_uart component is still managed with snd_device. It's for the case where the mpu401_uart component may be removed dynamically without the actual device unbind. Signed-off-by: Takashi Iwai --- sound/drivers/mpu401/mpu401.c | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c index d0b55dbb411a..66b94f73956f 100644 --- a/sound/drivers/mpu401/mpu401.c +++ b/sound/drivers/mpu401/mpu401.c @@ -59,8 +59,8 @@ static int snd_mpu401_create(struct device *devptr, int dev, snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n"); *rcard = NULL; - err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE, - 0, &card); + err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE, + 0, &card); if (err < 0) return err; strcpy(card->driver, "MPU-401 UART"); @@ -76,15 +76,11 @@ static int snd_mpu401_create(struct device *devptr, int dev, irq[dev], NULL); if (err < 0) { printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]); - goto _err; + return err; } *rcard = card; return 0; - - _err: - snd_card_free(card); - return err; } static int snd_mpu401_probe(struct platform_device *devptr) @@ -105,20 +101,12 @@ static int snd_mpu401_probe(struct platform_device *devptr) if (err < 0) return err; err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } platform_set_drvdata(devptr, card); return 0; } -static int snd_mpu401_remove(struct platform_device *devptr) -{ - snd_card_free(platform_get_drvdata(devptr)); - return 0; -} - #define SND_MPU401_DRIVER "snd_mpu401" static struct platform_driver snd_mpu401_driver = { @@ -184,10 +172,8 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, if (err < 0) return err; err = snd_card_register(card); - if (err < 0) { - snd_card_free(card); + if (err < 0) return err; - } pnp_set_drvdata(pnp_dev, card); snd_mpu401_devices++; ++dev; @@ -196,19 +182,10 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, return -ENODEV; } -static void snd_mpu401_pnp_remove(struct pnp_dev *dev) -{ - struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev); - - snd_card_disconnect(card); - snd_card_free_when_closed(card); -} - static struct pnp_driver snd_mpu401_pnp_driver = { .name = "mpu401", .id_table = snd_mpu401_pnpids, .probe = snd_mpu401_pnp_probe, - .remove = snd_mpu401_pnp_remove, }; #else static struct pnp_driver snd_mpu401_pnp_driver;