From patchwork Sun Mar 26 14:41:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 9645409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6440B602BF for ; Mon, 27 Mar 2017 07:09:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5213D28334 for ; Mon, 27 Mar 2017 07:09:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4504F2832D; Mon, 27 Mar 2017 07:09:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A4492832D for ; Mon, 27 Mar 2017 07:09:20 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id B2C3B266C6E; Mon, 27 Mar 2017 09:07:59 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id AF98D266BFF; Sun, 26 Mar 2017 16:42:51 +0200 (CEST) Received: from mail-wr0-f176.google.com (mail-wr0-f176.google.com [209.85.128.176]) by alsa0.perex.cz (Postfix) with ESMTP id 0078B266BF6 for ; Sun, 26 Mar 2017 16:42:47 +0200 (CEST) Received: by mail-wr0-f176.google.com with SMTP id u1so22389698wra.2 for ; Sun, 26 Mar 2017 07:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kg1tHTicO5RHrZ7CvtEBKgDIkiFAiw69YL/8YdjT9o0=; b=Rq8wVndWfxR+yx0k0AWVKAqtXzpRmDLyOePbw52PecCruYmqvF/z66b3mHGBfCkpYT GeqYlsi2O2J7Fg84GJfVuhF/9ifeRDxsTT2uEZG4obkU2vNNfP+SW9tJveVhpsviXvvE ALgnI95lt1X8Tnapf5hDufVhlQTCqcofmZjD8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Kg1tHTicO5RHrZ7CvtEBKgDIkiFAiw69YL/8YdjT9o0=; b=Ir8EF17k8p81ynfEmq9XobU9yFokjzfvVqcdUK4QUOO0AY7F1enaq+DkDC0mcSPXtf 7IXzXZ/OdAsCijo/Uymq43V+DsADfw2rta4Vj39FJ+7L9XkfC6ZSh7ZjBhDiVmSyFwZH D3SuCR8UYVuaVsMBIq8hrap5kbNS7KzIgwOU1+iO6pA/k/TX2ecpR0K3AftI7I+3Agm8 KMJuhwcQTG9P33f++qHfqNxnLFmmG9imoeYSdKq59tjoc9O29dc31EGGat0IRrBTG3St 5ylqc/jjfQWrR5XkBHWKSOVDgjmhH8h9/fbLiWwOLJIpak6Fy0BOLKikLRTOxRVlTfOy R0VQ== X-Gm-Message-State: AFeK/H2njGTJ2jtIRtOGBcALRLtJnew00w1Mkm+JOvCQLvSBRTigZ4HN4cr3AQkBDh/lhNIV X-Received: by 10.223.166.162 with SMTP id t31mr2208119wrc.15.1490539366996; Sun, 26 Mar 2017 07:42:46 -0700 (PDT) Received: from localhost.localdomain (li1529-187.members.linode.com. [139.162.244.187]) by smtp.gmail.com with ESMTPSA id l90sm10619516wmi.25.2017.03.26.07.42.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Mar 2017 07:42:46 -0700 (PDT) From: Leo Yan To: Russell King , Dmitry Torokhov , Alessandro Zummo , Alexandre Belloni , Linus Walleij , Baptiste Reynal , Alex Williamson , Jaroslav Kysela , Takashi Iwai , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, rtc-linux@googlegroups.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, alsa-devel@alsa-project.org Date: Sun, 26 Mar 2017 22:41:53 +0800 Message-Id: <1490539314-9681-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490539314-9681-1-git-send-email-leo.yan@linaro.org> References: <1490539314-9681-1-git-send-email-leo.yan@linaro.org> X-Mailman-Approved-At: Mon, 27 Mar 2017 09:07:53 +0200 Cc: Leo Yan Subject: [alsa-devel] [PATCH 4/5] vfio: platform: Convert to use devm_*() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Convert driver to use devm_*() APIs so rely on driver model core layer to manage resources. This eliminates error path boilerplate and makes code neat. This patch also renames amba_id structure, the old code used some code which directly copied from other driver. Signed-off-by: Leo Yan --- drivers/vfio/platform/vfio_amba.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c index 31372fb..433db1f 100644 --- a/drivers/vfio/platform/vfio_amba.c +++ b/drivers/vfio/platform/vfio_amba.c @@ -53,15 +53,14 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id) struct vfio_platform_device *vdev; int ret; - vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); + vdev = devm_kzalloc(&adev->dev, sizeof(*vdev), GFP_KERNEL); if (!vdev) return -ENOMEM; - vdev->name = kasprintf(GFP_KERNEL, "vfio-amba-%08x", adev->periphid); - if (!vdev->name) { - kfree(vdev); + vdev->name = devm_kasprintf(&adev->dev, GFP_KERNEL, + "vfio-amba-%08x", adev->periphid); + if (!vdev->name) return -ENOMEM; - } vdev->opaque = (void *) adev; vdev->flags = VFIO_DEVICE_FLAGS_AMBA; @@ -71,11 +70,6 @@ static int vfio_amba_probe(struct amba_device *adev, const struct amba_id *id) vdev->reset_required = false; ret = vfio_platform_probe_common(vdev, &adev->dev); - if (ret) { - kfree(vdev->name); - kfree(vdev); - } - return ret; } @@ -84,25 +78,22 @@ static int vfio_amba_remove(struct amba_device *adev) struct vfio_platform_device *vdev; vdev = vfio_platform_remove_common(&adev->dev); - if (vdev) { - kfree(vdev->name); - kfree(vdev); + if (vdev) return 0; - } return -EINVAL; } -static struct amba_id pl330_ids[] = { +static struct amba_id vfio_ids[] = { { 0, 0 }, }; -MODULE_DEVICE_TABLE(amba, pl330_ids); +MODULE_DEVICE_TABLE(amba, vfio_ids); static struct amba_driver vfio_amba_driver = { .probe = vfio_amba_probe, .remove = vfio_amba_remove, - .id_table = pl330_ids, + .id_table = vfio_ids, .drv = { .name = "vfio-amba", .owner = THIS_MODULE,