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: 9645049 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 0BC10601E9 for ; Sun, 26 Mar 2017 14:43:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F12DE23B23 for ; Sun, 26 Mar 2017 14:43:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5E1C27F94; Sun, 26 Mar 2017 14:43:49 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9DDC127F89 for ; Sun, 26 Mar 2017 14:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fUk8Kn2pVjIenqpTFoCDBy+T6UNomjQOOJpMciEcbFE=; b=lOQbDRtvfVZnzQmM2ICK2JCgOZ zOWq6S1fk8P2JiSJGDLaNqvYLG6L+pR8qGB+umP0x3KEdWva+o+teehp+m8oYbZb31EKeKfuHHXME oeLuOzfJtWwNWGP9P0npq2IrBup74wFI6zl+ASs3iJG/eK2+vaXMxGi3NMujqn7xw16pR1YZNtZqV zhQ5zEyfpq1glmBW2C7uxfnTzElMeJv+z/Ry2NCPHeoQ/sBXs/15k5K71EIWYWHCsJiI138Rk2NVJ 7vOY+pjPoWFH/TiF4dr7fVc7i6l8JAIw7eb7wIB80IkIkxgmZ9hqRB8CgbF9Vj3t+h8oGT+hzQpq5 7xihycxQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cs9OX-0004EY-6V; Sun, 26 Mar 2017 14:43:49 +0000 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cs9Ns-0003Y0-Sl for linux-arm-kernel@lists.infradead.org; Sun, 26 Mar 2017 14:43:10 +0000 Received: by mail-wr0-x234.google.com with SMTP id u1so22389699wra.2 for ; Sun, 26 Mar 2017 07:42:48 -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=NrnTptbOe8X+FyboNvCXcVgmiSVx1l9YtVtm7qzlDD2oKn2Oe5cPhcrEWLngg9ybYm HuXrAIU9jwtnRTeTuy4fdq2pLCwNgfX9obZz1lmeT4gp7eLku7+BoywH51QBP4kv3yJW 6GzeTf/0VDLYlj19kSluvZ4KYaWw8NNTHGb+xdLqlN+jnt7EYAE1PvEO3w9yluDCadKs 0r8o2oRZobp2GKRQxBEC7e+UuVWJTeXSoOhe5HqU0WBf7Tr3zTnqfbKuEGvo0CFzg+R4 ucBXBvw2eJgxdUghoj5rPik5UknANzsY9VO4nAOaKDfzoLiXDcqF4SMT538DRfjJvKBP UbjA== X-Gm-Message-State: AFeK/H1QLfnktiidhl7l43iwlh+NHdGq00GRRd/tCBFm6K0JQfAspvDrqitRK4dHy8Sea8GU 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 Subject: [PATCH 4/5] vfio: platform: Convert to use devm_*() 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170326_074309_145669_D44190B9 X-CRM114-Status: GOOD ( 13.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 Reviewed-by: Eric Auger --- 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,