From patchwork Sun Sep 30 20:26:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10621491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD8166CB for ; Sun, 30 Sep 2018 20:26:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CC3B292A8 for ; Sun, 30 Sep 2018 20:26:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90AFB29315; Sun, 30 Sep 2018 20:26:40 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F908292A8 for ; Sun, 30 Sep 2018 20:26:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4863E6B000C; Sun, 30 Sep 2018 16:26:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3651B6B000D; Sun, 30 Sep 2018 16:26:28 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E6456B000E; Sun, 30 Sep 2018 16:26:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by kanga.kvack.org (Postfix) with ESMTP id AFC136B000C for ; Sun, 30 Sep 2018 16:26:27 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id q15-v6so14102854wrw.1 for ; Sun, 30 Sep 2018 13:26:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=O0syVcyhMbKhyp2iqYZ+ip089O6apq5xjZEumPKtFH0=; b=GyaHjwPqxM0RToYyLq0UWche9RUopbHpTMjLwnwHJkPpyCL+Rci93Cp244Ni5Ai9c+ LLNUZA/7AxR0fJrJD0sJkMmVKWM2aFXHLczdufMd89Uq5auvDuI6Mp3fcTEIQiifsmjW QeeJ0p9dxUq9x+m8yQusqYH2VrWSfO6fNW+2BNxBtoOXbdGp25rwNjAvhNrzOIV0JCMF quKsU0nPtg0xmgMscVNBhSJUpkctmM8wZ85GfxMbjUbpSAML1NFtCnw04QgrmUk8ux5v QUyBi2YC4ynaHNQKf1kLlcGD7PymicwCdQuUIeXE0mx+uSk0rPTgwgOwUmVxyJ8+2mbO 1eEg== X-Gm-Message-State: ABuFfoh6eAvctlK6CXhPu3Utp06lOvh3HnFPq0Fxeq1M2UkESZnqAt6Y cNorCaQX2yo1we4MAnT8rS+FNkTpeo+mya2ETAoOC7CYvBz0fCQ5VgvPlvohdn8CMBsBa8bYjew T1xiala84nPtI9fw7IZ0nOsw2zFjFkxMJ120F6pIFIWETiLJqMLqHfpUtQBI4vQzFODHDob7+Ad 65Lrh0r7Sq8nivMnjJAdq/kou0i/Fe2HvXhak1qlixFmDzDZRa+bvhxrDnsYPnPdouzwsx6FE1T EbbcH1+VhqVSmpTsMdb30ySB4t9pFOp2mv9oe+IazxyuS0hMXkA4tZU7eqdRAiYAxalf8/UQ55y WeqV819PPj3CpkiYxvIAFZ4vhBgrW88HcoeibX+5dqs7uaNs5MFzDYZDGcNmnQt/YaZAO8Xg5eg N X-Received: by 2002:adf:81e1:: with SMTP id 88-v6mr96518wra.19.1538339187229; Sun, 30 Sep 2018 13:26:27 -0700 (PDT) X-Received: by 2002:adf:81e1:: with SMTP id 88-v6mr96494wra.19.1538339186288; Sun, 30 Sep 2018 13:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538339186; cv=none; d=google.com; s=arc-20160816; b=cUlgAgkkqzHme2afarVW9Bdwv+LgyxzXjtFv76QfnUcQac+jyunaCBphuHuiWY8R4q vWPmpU5nSY/QTp+HXksXzxuYf8e+7MZioGUADIgfqz9o5mHH8E0HsoYjpYovK8bIdxCG pvJGLvp/E/clPV849ilDmjlw5W4HO3lNCDZQU6exHZTJqvsYqX9Wy5il/YPIn7RTZro4 haK3OOgqA5lmVLh4T4Pz5/WJtqR3rl/BLqS6tRymqxrvA/Jfwi2oNWw/mdoAehOR3uE4 x8x71ydmHAEyVRkOTv3Tk8de71xDox4lU4d81tolMiRCeO9pil0DcxqSlbCe88w1Gk6u JaCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O0syVcyhMbKhyp2iqYZ+ip089O6apq5xjZEumPKtFH0=; b=V1usWfb99qKvauoU11eIVCp5N4kNL3CyMK3f+iXu8uAoY5wLcaPHNV/tSx1ZiaE5k+ Nayjw+HURoiOeC8Nmq9Ub+lXJcuVCyPFKbqcLgOQmkq27jWuNTi5lFMqNVcs1Z6BJE4F 16kBgHdBHxhO8gxGxQl4UULfLvs1gQ6Gn2v8nNDCvfl+wIlR5LCASKPuXyI5jYnTBnv9 GjS0I1v4b1GICDEd0s7ZuiZzLcRXT5rcwK86Uxp+dlmdCSxHAJHkVpIIMRaq3lasF6c7 +kJVwGsIAlJ0JWed1dH4vrnS3Jek1o2zVgqcb0Zbugs2JgmFvX5ZDg+WDWQL5uxkbfe9 vnKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="w7W/tX/T"; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of brgl@bgdev.pl) smtp.mailfrom=brgl@bgdev.pl Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x18-v6sor4934898wmi.11.2018.09.30.13.26.26 for (Google Transport Security); Sun, 30 Sep 2018 13:26:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of brgl@bgdev.pl) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="w7W/tX/T"; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of brgl@bgdev.pl) smtp.mailfrom=brgl@bgdev.pl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=O0syVcyhMbKhyp2iqYZ+ip089O6apq5xjZEumPKtFH0=; b=w7W/tX/T82M7c8f+3bIhAve5JFO+DY5Rq/2i2fCIRsiRQ6Ly2dYZBl765fvH24WH3G JmCG9rlZHdOA5Ql9EhsPMPtx4PhSptEP/anrdZwDMWQ+lOkwszTGMTRV8RSg/8MXlwAR rQdYV8kY/ZAgCE+HPYsd7/vaq0PaVDoCTC+BpKXjuDgzX5HZZ8o/F28itZW5DtjfFxnw 8a+HeuypnIZv3RoniHbHyB47mTjJnw73pzV7nRUYwx6KgVMnSa+xlY8PfJK2lMMdIt9F N77seMORgsw5Giqy3bC8gtZs1bbzcOl3S/wOD3nEhHar2VQtVaosedt71ZsWMCy1Mfyr vmOw== X-Google-Smtp-Source: ACcGV63VEVVK1jkBPOt9G/PKx3iIU00AOIjNPTudis33UXJEKkC/iwZgNmYbzNkIdlYHsIL4ih0TvQ== X-Received: by 2002:a1c:7015:: with SMTP id l21-v6mr6843040wmc.81.1538339185950; Sun, 30 Sep 2018 13:26:25 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id v16-v6sm18566465wrw.12.2018.09.30.13.26.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 13:26:25 -0700 (PDT) From: Bartosz Golaszewski To: Greg Kroah-Hartman , "Rafael J . Wysocki" , Jassi Brar , Thierry Reding , Jonathan Hunter , Arnd Bergmann , Andy Shevchenko , Geert Uytterhoeven , Rasmus Villemoes Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v6 4/4] mailbox: tegra-hsp: use devm_kstrdup_const() Date: Sun, 30 Sep 2018 22:26:15 +0200 Message-Id: <20180930202615.12951-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180930202615.12951-1-brgl@bgdev.pl> References: <20180930202615.12951-1-brgl@bgdev.pl> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Use devm_kstrdup_const() in the tegra-hsp driver. This mostly serves as an example of how to use this new routine to shrink driver code. Also use devm_kzalloc() instead of regular kzalloc() to get shrink the driver even more. Doorbell objects are only removed in the driver's remove callback so it's safe to convert all memory allocations to devres. Signed-off-by: Bartosz Golaszewski --- drivers/mailbox/tegra-hsp.c | 41 ++++++++----------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c index 0cde356c11ab..106c94dedbf1 100644 --- a/drivers/mailbox/tegra-hsp.c +++ b/drivers/mailbox/tegra-hsp.c @@ -183,14 +183,15 @@ static irqreturn_t tegra_hsp_doorbell_irq(int irq, void *data) } static struct tegra_hsp_channel * -tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, - unsigned int master, unsigned int index) +tegra_hsp_doorbell_create(struct device *dev, struct tegra_hsp *hsp, + const char *name, unsigned int master, + unsigned int index) { struct tegra_hsp_doorbell *db; unsigned int offset; unsigned long flags; - db = kzalloc(sizeof(*db), GFP_KERNEL); + db = devm_kzalloc(dev, sizeof(*db), GFP_KERNEL); if (!db) return ERR_PTR(-ENOMEM); @@ -200,7 +201,7 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, db->channel.regs = hsp->regs + offset; db->channel.hsp = hsp; - db->name = kstrdup_const(name, GFP_KERNEL); + db->name = devm_kstrdup_const(dev, name, GFP_KERNEL); db->master = master; db->index = index; @@ -211,13 +212,6 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, return &db->channel; } -static void __tegra_hsp_doorbell_destroy(struct tegra_hsp_doorbell *db) -{ - list_del(&db->list); - kfree_const(db->name); - kfree(db); -} - static int tegra_hsp_doorbell_send_data(struct mbox_chan *chan, void *data) { struct tegra_hsp_doorbell *db = chan->con_priv; @@ -332,31 +326,16 @@ static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox, return chan ?: ERR_PTR(-EBUSY); } -static void tegra_hsp_remove_doorbells(struct tegra_hsp *hsp) -{ - struct tegra_hsp_doorbell *db, *tmp; - unsigned long flags; - - spin_lock_irqsave(&hsp->lock, flags); - - list_for_each_entry_safe(db, tmp, &hsp->doorbells, list) - __tegra_hsp_doorbell_destroy(db); - - spin_unlock_irqrestore(&hsp->lock, flags); -} - -static int tegra_hsp_add_doorbells(struct tegra_hsp *hsp) +static int tegra_hsp_add_doorbells(struct device *dev, struct tegra_hsp *hsp) { const struct tegra_hsp_db_map *map = hsp->soc->map; struct tegra_hsp_channel *channel; while (map->name) { - channel = tegra_hsp_doorbell_create(hsp, map->name, + channel = tegra_hsp_doorbell_create(dev, hsp, map->name, map->master, map->index); - if (IS_ERR(channel)) { - tegra_hsp_remove_doorbells(hsp); + if (IS_ERR(channel)) return PTR_ERR(channel); - } map++; } @@ -412,7 +391,7 @@ static int tegra_hsp_probe(struct platform_device *pdev) if (!hsp->mbox.chans) return -ENOMEM; - err = tegra_hsp_add_doorbells(hsp); + err = tegra_hsp_add_doorbells(&pdev->dev, hsp); if (err < 0) { dev_err(&pdev->dev, "failed to add doorbells: %d\n", err); return err; @@ -423,7 +402,6 @@ static int tegra_hsp_probe(struct platform_device *pdev) err = mbox_controller_register(&hsp->mbox); if (err) { dev_err(&pdev->dev, "failed to register mailbox: %d\n", err); - tegra_hsp_remove_doorbells(hsp); return err; } @@ -443,7 +421,6 @@ static int tegra_hsp_remove(struct platform_device *pdev) struct tegra_hsp *hsp = platform_get_drvdata(pdev); mbox_controller_unregister(&hsp->mbox); - tegra_hsp_remove_doorbells(hsp); return 0; }