From patchwork Thu Nov 8 16:46:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 995011 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-tegra-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="naS9MWxJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42rTgv2TF9z9s8J for ; Fri, 9 Nov 2018 03:46:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbeKICWg (ORCPT ); Thu, 8 Nov 2018 21:22:36 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51494 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726585AbeKICWg (ORCPT ); Thu, 8 Nov 2018 21:22:36 -0500 Received: by mail-wm1-f68.google.com with SMTP id w7-v6so1942731wmc.1 for ; Thu, 08 Nov 2018 08:46:16 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=BXL2oXxjpuNjWt/hucj26s9Y9MA48Yp9jON68YMd/JY=; b=naS9MWxJPZEYXzoKH9Lz5a5eMGeiH3wAk9e8Nxn/wOkBj/rGu/L5uD8VNzAD5BimjC MJ3W/JVGZGUdZsVFH9VmC6Da4gJY/wbIfkQGCwd0Tk0W/LiNaB0EelpIRcIr7UIg1Q/u rPEqPruWf52tDD7u4fdH4veOzpoFVi+4m3lgRyJLdYlIrO1/OixqbsSA6booJjCh5xbP t9cu/3nhBd7vO5R2hry0i+1uEVGX9Z9lt++Z4P/vb6CE4HMqa4zscq3j3Gk8i+09JcBs i3m/WgvjXbuqr8RBRtyzkumjPofShHpnspjLISZxK0Espfn1ZsFW2nSHvAO10RpT30lK tQyw== 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:mime-version :content-transfer-encoding; bh=BXL2oXxjpuNjWt/hucj26s9Y9MA48Yp9jON68YMd/JY=; b=fUUbiCwsRc5ueap4QqEA2XyAg2QcrhWe84+/RXO6LHRq19ldDj2S/0LcdXaGItJigr 7lFcQGU1p75mXuaXt9oL4TwqaHRVLBoX+P7wgT0CaXHsR4gttJersiru17hGUAaRUHFm WysIO+uNJ2BNn4UlBm/4m2+Zm61/Yv8klZXOLEHvDDI26uEP9Gi5uxWI2R0cdbQAzod5 Y5NmeDk98hjHyql7ysNulZvhOSmmnnjGMa8EIIYv3p/QO9msRpajaHtB8d01omwE0uKr Mm8S7xuRQmmVP2Y45LMYATrEHQD5oQCpu5oF6gEJ+gV53NJI2HxlBHJOOUlqyL2Ue6Q0 yMkQ== X-Gm-Message-State: AGRZ1gK4ACd/iOP5VMC524vLw1pVyjN00STGPoAWnXeIgMcHYgnffcHC E94Yqq4oTH+uvdfbuWEsNKkhHw== X-Google-Smtp-Source: AJdET5dkkzKokK3Z155wSb+6AwD4tAbKJWqacEhRDjkG8vRFf6PWTyj/qcRV6jvo1ZeYOsukRRNl5w== X-Received: by 2002:a1c:ce0e:: with SMTP id e14-v6mr1781539wmg.45.1541695575251; Thu, 08 Nov 2018 08:46:15 -0800 (PST) Received: from debian-brgl.lan ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id w11-v6sm4425591wrr.96.2018.11.08.08.46.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Nov 2018 08:46:14 -0800 (PST) From: Bartosz Golaszewski To: Jassi Brar , Thierry Reding , Jonathan Hunter Cc: linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH] mailbox: tegra-hsp: use devm_kstrdup_const() Date: Thu, 8 Nov 2018 17:46:10 +0100 Message-Id: <20181108164610.28361-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org 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 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; }