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: 96014 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp853458qgd; Sun, 26 Mar 2017 07:43:14 -0700 (PDT) X-Received: by 10.84.217.2 with SMTP id o2mr23492426pli.51.1490539394286; Sun, 26 Mar 2017 07:43:14 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a74si6836527pfj.78.2017.03.26.07.43.14; Sun, 26 Mar 2017 07:43:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-input-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-input-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751518AbdCZOmz (ORCPT + 1 other); Sun, 26 Mar 2017 10:42:55 -0400 Received: from mail-wr0-f172.google.com ([209.85.128.172]:35360 "EHLO mail-wr0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751513AbdCZOmy (ORCPT ); Sun, 26 Mar 2017 10:42:54 -0400 Received: by mail-wr0-f172.google.com with SMTP id u1so22389700wra.2 for ; Sun, 26 Mar 2017 07:42:52 -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=B2APEXNh0GGS417fQo6LAzlEhTn/HVG1u7VpKBq6OjNyUP7VAE8t/Ba6ildAym/aIv S+aPpKGKt3qV4VY1R+rVzeRty1CtwETXyXdL852ej3ldFHLLAbOXF9zKyOAMmZ5kn9NF agNP2AEw70kY9Kt8QnIZX09F6TUsUf3PTgKHdT12kHnrCd2TO3RT2I92z0cedmh2CjZG +b32C6v7jj4i4ukfX+nHt0YCJwmLXl6cm0kzG8hvkvseqNYIiHHYFDw8tYZcEaHd7nGv zgTwebliC1TUyEFw3OkjxbZg6jkZuLYVhK1YZFxqabl4K5Y3hnIRbao9DQ3IN8Njdexs qfUA== X-Gm-Message-State: AFeK/H2QLoCcvwmyCqUTlZrugOuTbqkbGMQexWQBhpu2tahWU3anaFRZA06ao8LjKAu6HRAg 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 Cc: Leo Yan 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> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Eric Auger 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,