From patchwork Fri Sep 28 07:14:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10619073 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 CCD9215A6 for ; Fri, 28 Sep 2018 07:14:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B829D2AA62 for ; Fri, 28 Sep 2018 07:14:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC2392AB1F; Fri, 28 Sep 2018 07:14:31 +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 2E8272AA62 for ; Fri, 28 Sep 2018 07:14:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8940F8E0003; Fri, 28 Sep 2018 03:14:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 81A458E0001; Fri, 28 Sep 2018 03:14:26 -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 6E25D8E0003; Fri, 28 Sep 2018 03:14:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by kanga.kvack.org (Postfix) with ESMTP id 100FB8E0001 for ; Fri, 28 Sep 2018 03:14:26 -0400 (EDT) Received: by mail-wm1-f69.google.com with SMTP id p4-v6so1079561wmc.1 for ; Fri, 28 Sep 2018 00:14:26 -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=38j/leseIFaYyx4yzFjMEUsIrw9mip1Szaiqm4tzm/A=; b=SPeOqlpOxL1P+e0y8Z1E+eoHkdPsq5vLsxxucm7IrVaxNz76VGoAlQfTtTkNP5pxMN 2RZL4Zix+zYSiDCv1Rnc6+dAF20PCiE8gnMpQq+aKWly+zcdmp12WDS37lHRCETBqyMy S+WJYWettK1PKGGdBjfTKyeW0vQBCrvtG3t6NFN49lA12ZTd6rP9blhGhjtmGanIA8wE mwWykfJ3Ya6rGUMKzJoOVMeO67GVQemkoRf/vBEzYeGIAQKDF5uh5BrAtZHiMjzixAir chs/2Kh6muNGASOuTpCbOWH0ootg4KlFdSVaO462XWfO2EeVhKZ5KzM0EQbFSbFNRATc ix/A== X-Gm-Message-State: ABuFfogBywkMh5zy4YCSuM/LRxkDj9rlZGzwYvqvOQbYcEqd40DIHUjM PEUM10BgqCAtKjGmNIceVPHGVxRJUv8k39VTxhftrelLqt6MSTbRpvUmsIb31pY8Sg3TBktcPDO w/bJ4NudMIZTE16IlofYcMaCHlRhqPj+5FZbzOWNThS/svJf0QJ6wNgOiOfeeK3LeKBvHNPTqhm 6x6R3LNBtdyNWs2cFsA8DWSE8xXjml0Ltz8xf8t8GLpx/OGXZnBm9d8lovxF5+gYMl2NSMwiZyh SXOJr07z9vxCBJMNd+iHi+kJvKmvJf+eHCiIWtUVvXIVcTaIhewwdC6n2qjEu/f/Xp95DU9tZzh /Wbhdl5JxbvWKCCaJXOed3gBRV0cHlVjhCo5SuIAPueN+rfeQiVclxFdSN38wPK9vYI2N+Lkmrq 0 X-Received: by 2002:a1c:f53:: with SMTP id 80-v6mr686756wmp.58.1538118865563; Fri, 28 Sep 2018 00:14:25 -0700 (PDT) X-Received: by 2002:a1c:f53:: with SMTP id 80-v6mr686705wmp.58.1538118864300; Fri, 28 Sep 2018 00:14:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538118864; cv=none; d=google.com; s=arc-20160816; b=V+hmI64Ah9qjcB+2iWxOEqN/bKpffYYbJwyEGu48KBPLEV5IhirvrUaQ8FcIelvrd0 1d1nxfHBs6Jwz90WjEtVILfEKDK3xH9r5cqNnLl0CbKV+9D9Mr77s5VlLi9uqYKouuMm taCpN0BWR6r4luWZpaeRdNy4j8CDyvreid9KIqm13/JpZD4eVKrapcaQAHqxxQwuXCLv V2JRBWEYhWm41BgN77WQ+PGTtHFlHWwCJhbeQPbBwkeaYwLBw9YX3d9+rtwz2+o7XuoH Zxq9fmpEKOgyjGuCgAn9G5j1cqJKW9shSNgHIAVpQjzIrGoxrsw6KUM841/WbbAIixfU /Hvw== 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=38j/leseIFaYyx4yzFjMEUsIrw9mip1Szaiqm4tzm/A=; b=Ia6ny+J4EJJutUJqSgkf8hzByvUFnGmWrb3hMd4bpTZoxLg0Ddym2dCEnMLPmSY4m4 QuQ1J390aAhhCwQ69LXVSUcS8+pufedfmZPr4drm0OvdiqPJyvF1kok+geWU4Y25ESjW Msd8jkEwHEkAXXLMCPZOF10i/CXbtz668oDsaho0IOdxuqSufYY7MfnXjntL+kR1/6BT oEA1g7vgFOmfsQ5gemKtan/5PdFcuLPWTRXNkyZMH/CSdcnOZKlHIMACM9WSuSTs6Yop mHfGovFpDgg9EeILdoOy/hDiNW0Tt/JPsGpOZ8z13JUgy/lp9VhAwBVcj/rfeQ/sl9sr NlHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="xZHB+j/b"; 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 d133-v6sor19982wmf.19.2018.09.28.00.14.24 for (Google Transport Security); Fri, 28 Sep 2018 00:14:24 -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="xZHB+j/b"; 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=38j/leseIFaYyx4yzFjMEUsIrw9mip1Szaiqm4tzm/A=; b=xZHB+j/bjUkWuFfewEWNphV9YJEvenWMiyVbvCSju9sIKOcbGRR3UWIdjouNJQdea9 0HRG8gdIgaZcZ33syKrHxhkweUi85XYkucxPaGupl++jNMcnX0Hb1WfurRj3idIUSj6H kP6n8Mc5KLmPliGjvB5ZyU29/7gKL0K7oJD1vgFehOZNQvDiN2FQqHhzkEBR862tbryP w+owBeCV5sDcDbXI64lVYmgfKbCHUcStLUy9Jv1MBm7DO/jRVjiKII/OEGME9eeO2PAF ipjqovvgpp0UpL1Y/TTAW2F4/QDaVzSFCA3ZJD44oM8/ONaEmzKqwOcabwv2QEnK/1fp ebAw== X-Google-Smtp-Source: ACcGV62Ip6U1Gi1brHiX2B58GmseLhqeGNqwLC5svpHUnTYyV+a0H0N1hk95pywnAS5bhjqUL/eNkg== X-Received: by 2002:a1c:1802:: with SMTP id 2-v6mr721419wmy.81.1538118863900; Fri, 28 Sep 2018 00:14:23 -0700 (PDT) Received: from brgl-bgdev.sitez.s.ibrowse.com (93-158-26-51.subs.ibrowse.com. [93.158.26.51]) by smtp.gmail.com with ESMTPSA id w3-v6sm2699580wru.93.2018.09.28.00.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 00:14:23 -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 v5 1/4] devres: constify p in devm_kfree() Date: Fri, 28 Sep 2018 09:14:11 +0200 Message-Id: <20180928071414.30703-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180928071414.30703-1-brgl@bgdev.pl> References: <20180928071414.30703-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 Make devm_kfree() signature uniform with that of kfree(). To avoid compiler warnings: cast p to (void *) when calling devres_destroy(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Bjorn Andersson Reviewed-by: Geert Uytterhoeven --- drivers/base/devres.c | 5 +++-- include/linux/device.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index f98a097e73f2..438c91a43508 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -885,11 +885,12 @@ EXPORT_SYMBOL_GPL(devm_kasprintf); * * Free memory allocated with devm_kmalloc(). */ -void devm_kfree(struct device *dev, void *p) +void devm_kfree(struct device *dev, const void *p) { int rc; - rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, p); + rc = devres_destroy(dev, devm_kmalloc_release, + devm_kmalloc_match, (void *)p); WARN_ON(rc); } EXPORT_SYMBOL_GPL(devm_kfree); diff --git a/include/linux/device.h b/include/linux/device.h index 8f882549edee..33f7cb271fbb 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -692,7 +692,7 @@ static inline void *devm_kcalloc(struct device *dev, { return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); } -extern void devm_kfree(struct device *dev, void *p); +extern void devm_kfree(struct device *dev, const void *p); extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); From patchwork Fri Sep 28 07:14:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10619075 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 DF8F515A7 for ; Fri, 28 Sep 2018 07:14:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE8882AA62 for ; Fri, 28 Sep 2018 07:14:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1F8F2AB1F; Fri, 28 Sep 2018 07:14:34 +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 AA5322AA62 for ; Fri, 28 Sep 2018 07:14:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6006F8E0004; Fri, 28 Sep 2018 03:14:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5335A8E0001; Fri, 28 Sep 2018 03:14:27 -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 3D8238E0004; Fri, 28 Sep 2018 03:14:27 -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 D86018E0001 for ; Fri, 28 Sep 2018 03:14:26 -0400 (EDT) Received: by mail-wr1-f70.google.com with SMTP id v33-v6so5393624wrc.13 for ; Fri, 28 Sep 2018 00:14:26 -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=aahfn6W3XqbfPKSIMQjYMgIUnQeoDBftDVQeJAnnkHA=; b=koCHTEPDQcASG2dOtEP54PtSMFqSHG/B2IqdsRNnDhwjPa7whnKqWA96+T/uj6+X5S loGppQRbapMPx82o51V2LYNKri3V88hladopMIu/y5JQQfOo7ZNNE7zQPhrM+V1uFKvS daxp6C9Cy2X1QKikiiRtEXjTHJ8mWOU8dUwQ4mipQOOfstIVFeAhX+Q1hhce4Yzye3yS PN/aB7T1SdcjMX02v1WI6tpzK93kXrRMF1sF+Y7nD4oVu+kf56FtQ12ABJb+N+uyVoJl 2CTzKz22ulYcUzUQfeAu2NE2PdW70QE13Vo/YDEl/J+6Ti4BOQteBLzpUejJ6C4ntani Ie7w== X-Gm-Message-State: ABuFfojXeBkAXmB9j00Hp8QlzB4yPYDxeXidXl0bQ6jiMUs3iOUQENKu s/YQrA4MvJaiyp1rHJ3grW9b/aHXc1MTgmhZ4plCCuqEgtWydv8dWaoo56h6KV61G0nmustYZrc 21DxcH4+iTyYN1gn41z9ulXUhW1wKB/ksdev4Dx5plg6B3iRjHJ0/4NO+n5QKccwsdkJhjESfzh otwGm9RxK9JzDzhokSW2FRmSKlQkpZUEFu6/hbkvHdWvMrqMVxgrM1LhXQo+s1KvulDZ4HPb3z2 l4Fdw4GIFTB1CGqF8iACZwoWO8ZpX4O7mZCKmC3P4J/6Ch8/s0uEXZOSbPk3bqnJtyoQE7FZpEu 7kn+ujZIGDU4Efc4OqC0PZwh6QX9ZbunascScOEnT+BPKN8oLQZILhC2t/IzEmfQd6wKt5/wD0C 2 X-Received: by 2002:a1c:890:: with SMTP id 138-v6mr687879wmi.128.1538118866407; Fri, 28 Sep 2018 00:14:26 -0700 (PDT) X-Received: by 2002:a1c:890:: with SMTP id 138-v6mr687840wmi.128.1538118865509; Fri, 28 Sep 2018 00:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538118865; cv=none; d=google.com; s=arc-20160816; b=hVsux5L5MlLbqH5JZebh/vSER1hFYhaDlD/HP09dpg/5xwyfqxRAy1ylYmJtn8PH2d +AGLy40/SOhdyfM5Ft3Jc4wR72odFuaicq1bt90b0UUwHP6I9ZNcAaxAMvkEzu4W8+Gz FMEmZgPMzr1PeyD2riARrmYslYPp+da2cYGHphzmFpdxinI5I3CbntFP1N6ztZrhaam/ 6zfQAvHk8OooEvsnX4KUSAjz25L8776cTxXxvfrm4LJR1J0JPjcw1GDA7Oe++1ZQbbGP 93dJPRkXfK8LXkIQobwU+QBllQFq19cI4MuIfOmrcJatK2koSjqfbrMm+UAInFWPt5k9 rEzw== 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=aahfn6W3XqbfPKSIMQjYMgIUnQeoDBftDVQeJAnnkHA=; b=leSwP+zDzxQ5jw5vJyPsEzNn9+0YB0Mc3p8fgnuSxSZLyazezmHgJhLiWM+4lOfXHv HCwi2TaxGskozI6yR1qYlC24zFPteZPoqAdAvEWvrY3GpJMhSPw4s2gC5PruBc0NtvHs Y2CaGdzDtfOraLO488kq5NNbeXnsv3k0IqPoApc/J9VIpjKF5Kom5pQALVoah27/cf34 ArOYV/yH98SV6zx1Pa7SHcv91RxCN5uPao0b6aHSkXdPB+evJDkFMeDNhsy73+RSelzh KYjbquxc9lqwpuhPoDTVNIwlBX3Rq+qYkl4njSlmolKLPvoXQYX8ZpmNB/pPbP6y2yq7 3vRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=WcoMX+C9; 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 i8-v6sor3109752wrs.28.2018.09.28.00.14.25 for (Google Transport Security); Fri, 28 Sep 2018 00:14:25 -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=WcoMX+C9; 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=aahfn6W3XqbfPKSIMQjYMgIUnQeoDBftDVQeJAnnkHA=; b=WcoMX+C9r7Nhm6nWDcA0cWik7JPGoLzUMGxGlEyBvVT0v4JaG3FAcbtCBsSffzoNQQ 9NE2wgmzuC0gupcc0ODXgTmXUWWdbbwNEsZ/MDeL2P80n8bV3vzDufGm5Wul5F5nb2bz ZwGsS63plVXwHDRByuDDyspsS2y1TS/GCjsGmBm+To/eQJ7XDPLsGY7vjXkgQ6nXsvmh bLQhsAaDqw3/HxFpqClJ+S2JYXjXhlJveYBeiBlUC1BqCKyR+iy+j5wdKfnfLXDOSLSv 7IJAYRQsmMl6nmDKbYosByBPUdq5xi4XhAjLYKwPd+lJGlhffdA1JSQGb5InfFt65+z3 S30w== X-Google-Smtp-Source: ACcGV63dAIzBiNxrypnzZ7c/q17bjSFrJU94ofSqZ0yNmyySuop9DsNdLC9R2TnGlRQDb6WSwx9PxQ== X-Received: by 2002:a5d:4143:: with SMTP id c3-v6mr11258748wrq.61.1538118865099; Fri, 28 Sep 2018 00:14:25 -0700 (PDT) Received: from brgl-bgdev.sitez.s.ibrowse.com (93-158-26-51.subs.ibrowse.com. [93.158.26.51]) by smtp.gmail.com with ESMTPSA id w3-v6sm2699580wru.93.2018.09.28.00.14.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 00:14:24 -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 v5 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h Date: Fri, 28 Sep 2018 09:14:12 +0200 Message-Id: <20180928071414.30703-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180928071414.30703-1-brgl@bgdev.pl> References: <20180928071414.30703-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 Export this routine so that we can use it later in devm_kstrdup_const() and devm_kfree_const(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Bjorn Andersson Acked-by: Mike Rapoport Reviewed-by: Geert Uytterhoeven --- include/asm-generic/sections.h | 14 ++++++++++++++ mm/util.c | 7 ------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 849cd8eb5ca0..d79abca81a52 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -141,4 +141,18 @@ static inline bool init_section_intersects(void *virt, size_t size) return memory_intersects(__init_begin, __init_end, virt, size); } +/** + * is_kernel_rodata - checks if the pointer address is located in the + * .rodata section + * + * @addr: address to check + * + * Returns: true if the address is located in .rodata, false otherwise. + */ +static inline bool is_kernel_rodata(unsigned long addr) +{ + return addr >= (unsigned long)__start_rodata && + addr < (unsigned long)__end_rodata; +} + #endif /* _ASM_GENERIC_SECTIONS_H_ */ diff --git a/mm/util.c b/mm/util.c index 9e3ebd2ef65f..470f5cd80b64 100644 --- a/mm/util.c +++ b/mm/util.c @@ -15,17 +15,10 @@ #include #include -#include #include #include "internal.h" -static inline int is_kernel_rodata(unsigned long addr) -{ - return addr >= (unsigned long)__start_rodata && - addr < (unsigned long)__end_rodata; -} - /** * kfree_const - conditionally free memory * @x: pointer to the memory From patchwork Fri Sep 28 07:14:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10619077 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 3A87315A7 for ; Fri, 28 Sep 2018 07:14:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28C6E2AA62 for ; Fri, 28 Sep 2018 07:14:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C5EE2AB1F; Fri, 28 Sep 2018 07:14:37 +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 974162AA62 for ; Fri, 28 Sep 2018 07:14:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D1508E0005; Fri, 28 Sep 2018 03:14:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 759B98E0001; Fri, 28 Sep 2018 03:14: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 5F8538E0005; Fri, 28 Sep 2018 03:14:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id E8AC88E0001 for ; Fri, 28 Sep 2018 03:14:27 -0400 (EDT) Received: by mail-wm1-f72.google.com with SMTP id 199-v6so1250643wme.1 for ; Fri, 28 Sep 2018 00:14: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=mmvmbHeAPjG3Oc6euefkkNxK3Agi59+XcsUdVG7wIPA=; b=prNE+slDZypN/BWrACHrZH7wQcOPxpb7UJQqwLJsj4k+Vmv8+LV1hUiC2CteDvrkZu pg600dsAUeENnC2A05ly6YlnjEf2bJQaVLcxvJ3xj+V6IflFX+RmUJHUInK795chraZE KgXy/AxFtF0Y3v5ErlpkrbsTct8mEnWuilU5TMCCjg6/RXaICxFXwUeKloI3kH9EZMQF 2fcO1DXTj5i8/5zUBx+kuq2gYM0RgknZZJW/7hr1312haVfbN1mlTgtkcZgHJcOqJ3WU /ekOj8ri3QutdJgYoSgBxC1hKjjSEyARKYCg7Ym0OyzdQ4lvHK4eQ+TP76vtxn1ABBaz +dFw== X-Gm-Message-State: ABuFfogo6RuY6MNxCXy4MiWn5+XQfQCRNUsPGrvNjWarJyzyYP2Zuvlh PQbYtS2jpj6CXt2/bhUbTASUQyAx19HIh+xosiHaudjCABB5+yalErov9JeVGDtULHarP8y0nHJ DGyfBwg3vJ3lLLq1PTOZi3Rjco0+tv5A9CnxgBnuoU+E6Rg8cIyNrplOXTYo9nmm1Bwe67EcfHV 5ulFYfJi4ImsK2A/LUeLkL0N+piZE3VmTv0AGPYyfA8H1Uuqgmx/Ji/RZvt7Dl8xEESxlCYNbL0 lVw4HEkHC0WFz2CTtrVk+7iJXH7JthLA3/xOGzSa2uNbL2z7C7Sdgoe1J+IktXkpRE9qYoaia3Q MrPB+zCeb30HK9Keiva6Wt3J4LVElAKVYxSZoQkcwgAtvPI+b6HoK2IgaqZcLuOPsnsbso9yjCx Q X-Received: by 2002:a7b:c0d3:: with SMTP id s19-v6mr716543wmh.119.1538118867460; Fri, 28 Sep 2018 00:14:27 -0700 (PDT) X-Received: by 2002:a7b:c0d3:: with SMTP id s19-v6mr716498wmh.119.1538118866460; Fri, 28 Sep 2018 00:14:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538118866; cv=none; d=google.com; s=arc-20160816; b=XZx7l40wGmHSZeF/caFHvtdgOCg41993/BHvF136JmTit+Hd43/lqsNBeBxbjmcWlE 3DAdTTbST++sskbJT1ftao82TTmBmWThh54DRXi8rj/5nI2KcDKCCgM3MUTZBKu7aUi0 bmJuw69EiL6LT5tukVx/ua+NCHcpOioT85dNYbYJCzTrpMpXA7LGuxqmgEp2kI/9hu8Z jRjvGAb1kI0cb4g9u5lUTJafD2wVKtCYvj0xYI+3QFZr1jKYDmAUG7uXsyibMc6XpCuE YEdJ1MXJZCOZ4Tyw30sjlPy203qDHtF/tdt/SUEAaPdpbIGcj8tcS9GC1FgvAr/SjoAy KmLg== 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=mmvmbHeAPjG3Oc6euefkkNxK3Agi59+XcsUdVG7wIPA=; b=Wpk7wVpKT2Bj8QWeT62T7+lyMZDNpZTYwIkXeEGNLsdjs8oQr9V/i4fBK/VF1oh0jK EqXYKzUIz2xHNVv+j4xsDBpo492GRF654jvB1pQBW9/ketpSNDjIhe2gqAnG6gHNoyGM 71pGsSAMaRHASbD5qL/lZct1VDlzVZRM97/j0p3QaZL6WPtdk+BYsHJUIlVqf1lHciUt ZSDpvsGraC6krPStCel4YzRaCk28TqhEhvpphPDoGo/i39GD/dQP3KlyzKGvmgEeIEbE 8AW3eD0EZLomfntywOA6oOnFjBGXH1vA5ZH27g9vv7vWxBu4Ny2rzDw3eNQA1qdP2Dcy 0psg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=eNOYYAPc; 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 d9-v6sor3029036wrw.34.2018.09.28.00.14.26 for (Google Transport Security); Fri, 28 Sep 2018 00:14: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=eNOYYAPc; 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=mmvmbHeAPjG3Oc6euefkkNxK3Agi59+XcsUdVG7wIPA=; b=eNOYYAPccrzvANhkDNw26kqlmpRFu+n4SIXSBXPdEeJbPLkdD7VzMA9zRldxYzsL0X +ti+rePqmDBxnAfx3IAbg30up/VijzIanyusNpSFh7BzEI/xqN/lGWHi510Yt6d/65j4 HBKs5DMfCXIIjXzlmaMfb0YJ4En7HMInTqUKk2U9cMk9uHK36WXNfHpGTiP56Jto/kYY I9VlHJmzjC6kT9DzkxFXYjkA8L7j46qsio4ZQZw4Eu46M97VTPAoqv5a2GXMd8Ymewvr LWMHPo+Ef7Q/atDKfBO9SwnhHLsbcgqcMmXYDgwEBTDM/dDyAKCoV2Llbs8XPpTcwhd/ 4K+A== X-Google-Smtp-Source: ACcGV60diTTFYUDpbOd928mTZZjaS5tbfO/hDV+qcR0JJz+7sxMuxuKOO395Mt1wYQ+8c3XChxeJEQ== X-Received: by 2002:adf:bacf:: with SMTP id w15-v6mr11524709wrg.203.1538118866072; Fri, 28 Sep 2018 00:14:26 -0700 (PDT) Received: from brgl-bgdev.sitez.s.ibrowse.com (93-158-26-51.subs.ibrowse.com. [93.158.26.51]) by smtp.gmail.com with ESMTPSA id w3-v6sm2699580wru.93.2018.09.28.00.14.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 00:14: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 v5 3/4] devres: provide devm_kstrdup_const() Date: Fri, 28 Sep 2018 09:14:13 +0200 Message-Id: <20180928071414.30703-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180928071414.30703-1-brgl@bgdev.pl> References: <20180928071414.30703-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 Provide a resource managed version of kstrdup_const(). This variant internally calls devm_kstrdup() on pointers that are outside of .rodata section and returns the string as is otherwise. Make devm_kfree() check if the passed pointer doesn't point to .rodata and if so - don't actually destroy the resource. Signed-off-by: Bartosz Golaszewski Reviewed-by: Bjorn Andersson Acked-by: Mike Rapoport Reviewed-by: Geert Uytterhoeven --- drivers/base/devres.c | 31 +++++++++++++++++++++++++++++++ include/linux/device.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 438c91a43508..00c70f0fcdcd 100644 --- a/drivers/base/devres.c +++ b/drivers/base/devres.c @@ -11,6 +11,8 @@ #include #include +#include + #include "base.h" struct devres_node { @@ -822,6 +824,28 @@ char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) } EXPORT_SYMBOL_GPL(devm_kstrdup); +/** + * devm_kstrdup_const - resource managed conditional string duplication + * @dev: device for which to duplicate the string + * @s: the string to duplicate + * @gfp: the GFP mask used in the kmalloc() call when allocating memory + * + * Strings allocated by devm_kstrdup_const will be automatically freed when + * the associated device is detached. + * + * RETURNS: + * Source string if it is in .rodata section otherwise it falls back to + * devm_kstrdup. + */ +const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp) +{ + if (is_kernel_rodata((unsigned long)s)) + return s; + + return devm_kstrdup(dev, s, gfp); +} +EXPORT_SYMBOL(devm_kstrdup_const); + /** * devm_kvasprintf - Allocate resource managed space and format a string * into that. @@ -889,6 +913,13 @@ void devm_kfree(struct device *dev, const void *p) { int rc; + /* + * Special case: pointer to a string in .rodata returned by + * devm_kstrdup_const(). + */ + if (unlikely(is_kernel_rodata((unsigned long)p))) + return; + rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, (void *)p); WARN_ON(rc); diff --git a/include/linux/device.h b/include/linux/device.h index 33f7cb271fbb..e626acb93ef5 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -694,6 +694,8 @@ static inline void *devm_kcalloc(struct device *dev, } extern void devm_kfree(struct device *dev, const void *p); extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; +extern const char *devm_kstrdup_const(struct device *dev, + const char *s, gfp_t gfp); extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp); From patchwork Fri Sep 28 07:14:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10619079 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 76B5315A6 for ; Fri, 28 Sep 2018 07:14:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64DCE2AA62 for ; Fri, 28 Sep 2018 07:14:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58A972AB1F; Fri, 28 Sep 2018 07:14: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 C95522AA62 for ; Fri, 28 Sep 2018 07:14:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86D088E0006; Fri, 28 Sep 2018 03:14:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 81A778E0001; Fri, 28 Sep 2018 03:14:29 -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 6BBD68E0006; Fri, 28 Sep 2018 03:14:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by kanga.kvack.org (Postfix) with ESMTP id 0FCD08E0001 for ; Fri, 28 Sep 2018 03:14:29 -0400 (EDT) Received: by mail-wm1-f72.google.com with SMTP id z23-v6so1236676wma.2 for ; Fri, 28 Sep 2018 00:14:29 -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=qg3G/pZ/NrnCaIQcNAa+HqeBuyV0vj8Mt6QZx0izoS5+0DVQu/4v+wm1vWIM5gHsyC CgxxsgMHcN0LZx3r9deySRYDieP07AX797WrA34HicqaxrKJQrV3qHvuLQOXbn3jklxP pLIKn8MuwdNVEXxgTymWz+YtyedRS5KdmL/zliBN9NYxkYcPdoWC9TV19gZGNZgD/0Zh do+J6aLVnd0/NQ4j2y8yySy0wsgbrHJSWhhtB+PI5jR80SYX//hxwwkXZfAqf6F9AaSj SCXYFI3DnkYsfP8m8VV13ph1DOj4zzvr7SqR1xQRounWBw01dKmzaY6K8MYC9pgv24Ut IHNA== X-Gm-Message-State: ABuFfohjw6XkG0EqZVRFaj35pc3Br7fmDq9QCOneByDzfGkkWiWfEKRx ZUBzrp44hjnSlHvbZy6kmeK7B+uKQ/GZPShjEobprqGIHLnrsyUdi9iH1c5QEAocf1xeVlK77nq OpS3ct76HS1U2KrnPE9rEVnBOZgI2ZN1XuL8LN7BVUxaMueLb4f6rLjQleV0Xx39WKAA13yq3DW U7v/7+26I/EfZHrFLY33fOfGeDoISpUZ/Y19Cix9Vf5H0Y5jkNkWjF1rXCJlnvMIDQO6JrD6Cpy LFWgAzb55nCTZgV6bh76U9YQj+HJq77D383PPWAUU16Vb7uMUy32QsSKoOSni/G82n0YDJc6ZJZ fJgn3Tg8nZYUfWX7oU3HTKGHcN4ySEUTySax7h4XB7COC4N3X7wxR2Hh3OtXmr6e5qczauyk0Sk V X-Received: by 2002:a1c:974f:: with SMTP id z76-v6mr715017wmd.84.1538118868561; Fri, 28 Sep 2018 00:14:28 -0700 (PDT) X-Received: by 2002:a1c:974f:: with SMTP id z76-v6mr714983wmd.84.1538118867488; Fri, 28 Sep 2018 00:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538118867; cv=none; d=google.com; s=arc-20160816; b=aK1npIyfBgrxqxB6JSLhAmbK9BRKNgmrw2b4y2e+JM4XSzyKiM24M4iMRt5tXTf3pO mLnzqAjBzFwqeuPeX0D78paG4qAzyLUg1yzgrXbmn9lnQ4DTneJpuCOzx1YeG6YRFYVm mNaGGgcsfhUyIepcWdg2U7LNrBeNzdT3WWbc2osea45UIt3p9CMbYrQav9+ReuVjy0CI k2L5HOPDuFckSUnHJfLaqVtbz1Xv74o7+qtF9La9XylJBNPqnYNaQK2zOblimCuvupe3 Hj4QWXopzWm8ILLEaVP9cSuIKwQPdHmC8MLcN3Fp8sFcsARrdBGnHjfwhOiorcqi+yHM HeFw== 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=y6EruG8fAY+b5hgSPB/xwu5OnKgyNEgNnUZGuWFfHM4RlgsZGEl3qSACH3ZU0sbKNo /BXXsDPmILNf1tXpRzobYCPJuxSosdMcRmjPpzs/D+KfqKXUPAA6BXzZ7lMvkodIhL9W yY/BOIeGBQesUHLYL98wZ8s4dezIH+wEw/KK9mTk91tqRsNXWDOiIMn33ibBIwfHAPg/ rSh4drCr2QCvD5qmwK5aH81CAe3KhIM9BKPc9scS0IQSEh3CyREXtcemc626fI/jn+/m IQo8t8vsMj5jDJpqc+lMcWb8UsYCqNGRLUA5ALqs6YlSLjEvpNJR9vWPHvClK07fAYzL cqww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=eH5Bu5Tj; 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 b198-v6sor807405wme.27.2018.09.28.00.14.27 for (Google Transport Security); Fri, 28 Sep 2018 00:14:27 -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=eH5Bu5Tj; 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=eH5Bu5TjjtCkudqDsqgVImR5aSsVR9PfvdmPNwy0Ab3E3IEL7Wf8GNG13icu3K+SVe YeiOesAFjXCjNyCIdvwLaEm9Qg+6M8GVcDCD3hgP0cONHxeEKlCCiLYbvtNdNy2Q8Gs5 h4mYjaJeNoCmRJyFJSz8cPkcAcfAYUxeDok7X1Cb0ef+aKJ5bIk/qlAg+327GoJU2O7s PHjjJcEqgFZCXKtAqUHH1hSGWQV5crARB2a0vy9ldUPOrxhAefROKo1kW3yYw0Tge5x5 YxAhWBZ5iIj2V7s3W1sbn6BQNROXbtXNufEQkWGb7VSvFmEpN+8gJcWP/3NPQKE25gjw qOPA== X-Google-Smtp-Source: ACcGV62OtkYGNUVoag8MQ8Dim53QZGhQ76CQ7wFrYyT9hH7M+b6Jk0oCtMElLoxflnt871Kv8EjfuQ== X-Received: by 2002:a1c:b4d:: with SMTP id 74-v6mr683041wml.15.1538118867141; Fri, 28 Sep 2018 00:14:27 -0700 (PDT) Received: from brgl-bgdev.sitez.s.ibrowse.com (93-158-26-51.subs.ibrowse.com. [93.158.26.51]) by smtp.gmail.com with ESMTPSA id w3-v6sm2699580wru.93.2018.09.28.00.14.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 00:14:26 -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 v5 4/4] mailbox: tegra-hsp: use devm_kstrdup_const() Date: Fri, 28 Sep 2018 09:14:14 +0200 Message-Id: <20180928071414.30703-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180928071414.30703-1-brgl@bgdev.pl> References: <20180928071414.30703-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; }