From patchwork Tue Dec 5 22:16:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 10093897 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 7A7186056E for ; Tue, 5 Dec 2017 22:20:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BA1F29983 for ; Tue, 5 Dec 2017 22:20:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F8AB29915; Tue, 5 Dec 2017 22:20:05 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED 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 E333029582 for ; Tue, 5 Dec 2017 22:20:04 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:References:To:Subject:From:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kUG4gIG8TQfMQuH6X976kxj2TZ462QFGoz9FIKR8Ekw=; b=PIaovysQfCHZyG /QSn1pcWFMEkfqF+XjPx/vmPgSCcnpFydWxP9LC2XUHGHe7uiREZ3e9SaxQniCJS3Mx6Nknyj8kZg 3BA51bNbNBL2fmDMBAOvp0koXUdvTesuSgHcuhNJ1i+CwQAnr+DREtsuMTfItTT0GWdlddsAJ9UKr XcRWM9L0Nrj37QHJqP+3cvQUuGeTq1uRs14q2DJ6u/Zwf2yyrV2V/pkqxDgZk06so9hr3o3dk4l7U KbFg3kS5FgQDymzkxG87Wz/eCzovulkkq5YmoBoHw+hINrf0B/slMTpuMr+dnxyy4qRa+p20M5m5S txuLCveqmslFVi9Q77wQ==; 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 1eMLZL-0000fk-VQ; Tue, 05 Dec 2017 22:20:03 +0000 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMLXB-0006zO-66; Tue, 05 Dec 2017 22:17:52 +0000 Received: by mail-wr0-x244.google.com with SMTP id g53so1929331wra.2; Tue, 05 Dec 2017 14:17:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=kjkyqVu7bs9ps7W4Hs9zcAyF7QKvl8MqAF48kkRJNcc=; b=kNLbDpnZ9RzmxujRlKWDWZG2I7uzTCHw2a8GIs81x7sKFiyH7yhBfEgbFa3Xrft0bj icwzdiVNqg4TiF/AI7DISua3bk3eBsFL0POwJZwSfJiZIIVHpQdetzto6GyW0ZWC658S 9KEWthAuiqB1Tsl/yhC+fApaPOjLe8qfm5dapw8KvYHMAATK8pU4UUMBhTNA4Wc01oYM mo+1hU6JwbZDkq+yEfL9H537u5nG8IRmUAHRuXe9qq/+w6UIS2xx4C5nGBtIdcWOR2pD x7KOuNufdXY+T7rdaLyqxMZOWor9nWTWX5UfF4tryDZfmNef4rFCpPBJvHeW/ugHZ+rm 6gKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=kjkyqVu7bs9ps7W4Hs9zcAyF7QKvl8MqAF48kkRJNcc=; b=dthUT9ui3BtNXfzyRaTovvFL3T28uWJBCUv6Ao5FfmD6kCibgH25LSXkMOIGyPuGVt ITw884QDespr+g2Ld/HJdGXcMflnqyK5HXXV5Nut1OpDUE75jlp88xAcv8MGdMAZT4ux hlaCYi8gn8TpBLx4jN4PPmAJu4xipmnfAjJXRGdEKF+FwT+YvycLgbNC7ivDaT6tARw1 o/gVcr30jihPkRzOwaE9i1JrjtSGrh9wl9adqj4H4SAs5X6A0K6NE+qQuj1gTlriBHq1 yK+iouu5ta7JbWw/5PPOII4ubUJJKcCqmW0WSsbuA7CyLK+9Mg9FFwzmbYsJBdkrHKdT 1A5Q== X-Gm-Message-State: AJaThX6zzFGvG0Hmi9BNoaAEujuqu5sZkGa7VkqTo8WzzLjG4YAUj50e 6fPM/QupNSjLWodE/24HXTM= X-Google-Smtp-Source: AGs4zMZIUA+wqAYRrI6qusxMTwtr/KBWTf93AunSuJqYs9AM4xRmXE2XwkskGTYgWj3n6mYDQmu9SA== X-Received: by 10.223.195.138 with SMTP id p10mr19150477wrf.88.1512512247685; Tue, 05 Dec 2017 14:17:27 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:b595:9d9d:56de:88e3? (p200300EA8BC0E400B5959D9D56DE88E3.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:b595:9d9d:56de:88e3]) by smtp.googlemail.com with ESMTPSA id w76sm1444765wrc.79.2017.12.05.14.17.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 14:17:27 -0800 (PST) From: Heiner Kallweit Subject: [PATCH 02/12] firmware: arm_scpi: make freeing mbox channels device-managed To: Sudeep Holla References: <99220c79-8b35-2978-11d1-6d101ccb6772@gmail.com> Message-ID: <407a99ae-3e47-913c-b1e1-5548864a4ae5@gmail.com> Date: Tue, 5 Dec 2017 23:16:42 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <99220c79-8b35-2978-11d1-6d101ccb6772@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171205_141749_423355_7FF75149 X-CRM114-Status: GOOD ( 11.90 ) 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: "open list:ARM/Amlogic Meson..." , "linux-arm-kernel@lists.infradead.org" , Kevin Hilman 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 Make freeing the mbox channels device-managed, thus further simplifying scpi_remove and and one further step to get rid of scpi_remove. Signed-off-by: Heiner Kallweit --- drivers/firmware/arm_scpi.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index 2a30d255..4447738d 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -889,16 +889,13 @@ static struct attribute *versions_attrs[] = { }; ATTRIBUTE_GROUPS(versions); -static void -scpi_free_channels(struct device *dev, struct scpi_chan *pchan, int count) +static void scpi_free_channels(void *data) { + struct scpi_drvinfo *info = data; int i; - for (i = 0; i < count && pchan->chan; i++, pchan++) { - mbox_free_channel(pchan->chan); - devm_kfree(dev, pchan->xfers); - devm_iounmap(dev, pchan->rx_payload); - } + for (i = 0; i < info->num_chans; i++) + mbox_free_channel(info->channels[i].chan); } static int scpi_remove(struct platform_device *pdev) @@ -911,7 +908,6 @@ static int scpi_remove(struct platform_device *pdev) of_platform_depopulate(dev); sysfs_remove_groups(&dev->kobj, versions_groups); - scpi_free_channels(dev, info->channels, info->num_chans); platform_set_drvdata(pdev, NULL); for (i = 0; i < MAX_DVFS_DOMAINS && info->dvfs[i]; i++) { @@ -950,7 +946,6 @@ static int scpi_probe(struct platform_device *pdev) { int count, idx, ret; struct resource res; - struct scpi_chan *scpi_chan; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; @@ -967,13 +962,19 @@ static int scpi_probe(struct platform_device *pdev) return -ENODEV; } - scpi_chan = devm_kcalloc(dev, count, sizeof(*scpi_chan), GFP_KERNEL); - if (!scpi_chan) + scpi_info->channels = devm_kcalloc(dev, count, sizeof(struct scpi_chan), + GFP_KERNEL); + if (!scpi_info->channels) return -ENOMEM; - for (idx = 0; idx < count; idx++) { + ret = devm_add_action(dev, scpi_free_channels, scpi_info); + if (ret) + return ret; + + for (; scpi_info->num_chans < count; scpi_info->num_chans++) { resource_size_t size; - struct scpi_chan *pchan = scpi_chan + idx; + int idx = scpi_info->num_chans; + struct scpi_chan *pchan = scpi_info->channels + idx; struct mbox_client *cl = &pchan->cl; struct device_node *shmem = of_parse_phandle(np, "shmem", idx); @@ -981,15 +982,14 @@ static int scpi_probe(struct platform_device *pdev) of_node_put(shmem); if (ret) { dev_err(dev, "failed to get SCPI payload mem resource\n"); - goto err; + return ret; } size = resource_size(&res); pchan->rx_payload = devm_ioremap(dev, res.start, size); if (!pchan->rx_payload) { dev_err(dev, "failed to ioremap SCPI payload\n"); - ret = -EADDRNOTAVAIL; - goto err; + return -EADDRNOTAVAIL; } pchan->tx_payload = pchan->rx_payload + (size >> 1); @@ -1015,14 +1015,9 @@ static int scpi_probe(struct platform_device *pdev) dev_err(dev, "failed to get channel%d err %d\n", idx, ret); } -err: - scpi_free_channels(dev, scpi_chan, idx); - scpi_info = NULL; return ret; } - scpi_info->channels = scpi_chan; - scpi_info->num_chans = count; scpi_info->commands = scpi_std_commands; platform_set_drvdata(pdev, scpi_info);