Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2724747imm; Tue, 4 Sep 2018 09:02:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbmxyVI4HjlfypbmBNI6t0PxGwsnMFXsZecxmm60eS+7XAvy6PfV+L8hiXZ/oBfKn8datuY X-Received: by 2002:a62:56d9:: with SMTP id h86-v6mr11984391pfj.229.1536076927066; Tue, 04 Sep 2018 09:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536076927; cv=none; d=google.com; s=arc-20160816; b=ak2HVT0taKQsYPi6SS7vbScJ2L20JxNGg+DVOwzjhECptIUV7/0qWJFPrbvF/EAzVu 8d1jwQNVye7KiTu5/S/z+CtVyV9o407JRHksTwkuHEZuUPkTGkmgBOU56qP30IghuQA1 BRSupjqyZodXcI3wpD9qo3AL+PhgmTmUxCXU+hSty3WzulbC9xbFtP/by5ztmPDojI9j HlON1CeQm0H7rQUlRY2MDPi7skR01YL+f+2WAU6h7C961k/R33LyvGLbx73YOGYFUnwB wfENtY7EBTOzJIuHcytXQs/1li6Ndyye7wEEWhvHBK4o36gzxgtSddiZJ1ovumv8VpEX w6rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=zmmVEbR+e5dJCuYK4ZSheWjIHCnmlkvU5e/yAnaLDsU=; b=TcaWfNIWrgSPA85aTfSMGrxh1atwt2v/gK0TjTY7bvPLVVXmso+Hr4ka8UHxwQBc7/ vKgXYradD6kpa02c2z4KiVDqlzfFoAqKtIMQMh/dLhaJ599c8/X/qR/z6cyTc+xsu3D+ G0AQL6uazDk93wh+tgoMOglhUSqbBLik6NHvdxd4ryNdVRuq7d2qCryl//H5YneYPywG KvmeiQV6u9JMNYkxeDaT8i9Nwo4/sVpDfQSOXiLBySSyfUI2QVTmuX88Ox7d7icXofN5 gr5C86WWbcgwT8nD3kVLnjMQYaHM2CHAdreSev2GsbyzY0LTV6RFdnccqw2gH4ln9ktv pZqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x63-v6si22079788pfb.299.2018.09.04.09.01.43; Tue, 04 Sep 2018 09:02:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728078AbeIDUZp (ORCPT + 99 others); Tue, 4 Sep 2018 16:25:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:50972 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727770AbeIDUYv (ORCPT ); Tue, 4 Sep 2018 16:24:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9EB44B0B0; Tue, 4 Sep 2018 15:59:02 +0000 (UTC) From: Takashi Iwai To: Greg Kroah-Hartman Cc: Eric Anholt , Stefan Wahren , linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 21/29] staging: bcm2835-audio: Use card->private_data Date: Tue, 4 Sep 2018 17:58:50 +0200 Message-Id: <20180904155858.8001-22-tiwai@suse.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904155858.8001-1-tiwai@suse.de> References: <20180904155858.8001-1-tiwai@suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of allocating a separate snd_device object, let snd_card_new() allocate the private resource. This simplifies the code. Signed-off-by: Takashi Iwai --- .../vc04_services/bcm2835-audio/bcm2835.c | 91 +++---------------- 1 file changed, 13 insertions(+), 78 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c index 6876a5eadc07..55e7fbc3ec44 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c @@ -86,9 +86,6 @@ static int bcm2835_devm_add_vchi_ctx(struct device *dev) static void snd_bcm2835_release(struct device *dev) { - struct bcm2835_chip *chip = dev_get_drvdata(dev); - - kfree(chip); } static struct device * @@ -117,69 +114,6 @@ snd_create_device(struct device *parent, return device; } -/* component-destructor - * (see "Management of Cards and Components") - */ -static int snd_bcm2835_dev_free(struct snd_device *device) -{ - struct bcm2835_chip *chip = device->device_data; - struct snd_card *card = chip->card; - - snd_device_free(card, chip); - - return 0; -} - -/* chip-specific constructor - * (see "Management of Cards and Components") - */ -static int snd_bcm2835_create(struct snd_card *card, - struct bcm2835_chip **rchip) -{ - struct bcm2835_chip *chip; - int err; - static struct snd_device_ops ops = { - .dev_free = snd_bcm2835_dev_free, - }; - - *rchip = NULL; - - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - - chip->card = card; - mutex_init(&chip->audio_mutex); - - chip->vchi_ctx = devres_find(card->dev->parent, - bcm2835_devm_free_vchi_ctx, NULL, NULL); - if (!chip->vchi_ctx) { - kfree(chip); - return -ENODEV; - } - - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err) { - kfree(chip); - return err; - } - - *rchip = chip; - return 0; -} - -static struct snd_card *snd_bcm2835_card_new(struct device *dev) -{ - struct snd_card *card; - int ret; - - ret = snd_card_new(dev, -1, NULL, THIS_MODULE, 0, &card); - if (ret) - return ERR_PTR(ret); - - return card; -} - typedef int (*bcm2835_audio_newpcm_func)(struct bcm2835_chip *chip, const char *name, enum snd_bcm2835_route route, @@ -292,25 +226,26 @@ static int snd_add_child_device(struct device *device, return PTR_ERR(child); } - card = snd_bcm2835_card_new(child); - if (IS_ERR(card)) { + err = snd_card_new(child, -1, NULL, THIS_MODULE, sizeof(*chip), &card); + if (err < 0) { dev_err(child, "Failed to create card"); - return PTR_ERR(card); + return err; } - snd_card_set_dev(card, child); + chip = card->private_data; + chip->card = card; + chip->dev = child; + mutex_init(&chip->audio_mutex); + + chip->vchi_ctx = devres_find(device, + bcm2835_devm_free_vchi_ctx, NULL, NULL); + if (!chip->vchi_ctx) + return -ENODEV; + strcpy(card->driver, audio_driver->driver.name); strcpy(card->shortname, audio_driver->shortname); strcpy(card->longname, audio_driver->longname); - err = snd_bcm2835_create(card, &chip); - if (err) { - dev_err(child, "Failed to create chip, error %d\n", err); - return err; - } - - chip->dev = child; - err = audio_driver->newpcm(chip, audio_driver->shortname, audio_driver->route, numchans); -- 2.18.0