From patchwork Mon Sep 24 10:11:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10612171 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 7FB4913A4 for ; Mon, 24 Sep 2018 10:12:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E8C829ED2 for ; Mon, 24 Sep 2018 10:12:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 623E829EE3; Mon, 24 Sep 2018 10:12:21 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1508129ED2 for ; Mon, 24 Sep 2018 10:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728344AbeIXQN1 (ORCPT ); Mon, 24 Sep 2018 12:13:27 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35339 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727988AbeIXQNZ (ORCPT ); Mon, 24 Sep 2018 12:13:25 -0400 Received: by mail-wm1-f66.google.com with SMTP id o18-v6so9438695wmc.0 for ; Mon, 24 Sep 2018 03:12:04 -0700 (PDT) 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=Uy6pZDm6z/fl0jre25cfBjomNanGjgb8D5SlflebK4Dq53aCng4x8B/xsSiEuoljv3 101hdyhZJRdiq1/LK2s2DYanexvieCFQqeRwuu5m3dGgKgsSIvaLaJ9FbXuS23DChcPW aDm6egXgtPBVwFwDkSDQTGokT7Umb7qL+Wkt2AWw+Vx87mWsKncg/A43TTnFs7BlHu2H f+AFCKKUZJ/eD5mpxpoIAwgmjfB6WAcqUVHtGVgTlElhqcRjB8HsJ5Y/78uN2J9xQgvL LHgVUwyoSq6yH00fcHDUwjZDzxbVDgVYVhRvJSbr2ctIuIsTIdtQpNX8YuDqVb+KWpUP LVHg== 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=38j/leseIFaYyx4yzFjMEUsIrw9mip1Szaiqm4tzm/A=; b=iS14Sh7HKJhlZxoRLDEdoVi1R3MvvjXuzPgBYiv7N5sCfzxH0IWzK2XHeYZ96Aud+U HZxIOWPvT6vVqldSKP3ShYuMSwsxaBLYWGoq3xb7gf5VgL9Go3jO9IQHDsw9zoLzwdms lbUDawsJVwXKv4OxgRl8mPIhBnZjZhkIK451WiHrPQiKzpST3SmEwQD0tNCWHHOSB5OQ ur1Z9v/tvON4JI8htFLwxOPu003gEl17yYliJMzfPxX7PjrFKm1QdNK+HLGLEGSm/asv rgOdgDk3RRXNIycZ3ykUV1sqLje5Xr+EMuroS4HromJkTyjdUHeI6Jpbnr5NdPTQ3udj 2YQQ== X-Gm-Message-State: ABuFfogwYr0xn28lzRB3ADK8XQn7YUZaRoJvp6S5boW4VFrtw+Qen64G rObrFDMkMOv7clOBCCKAUE6uVA== X-Google-Smtp-Source: ACcGV605psT+bg6McVRzros1Jf9FORPXMAjXqmI/96ORXIfiqHRHrFOhI/+9JRilgZIocmyDiIQAdQ== X-Received: by 2002:a1c:4182:: with SMTP id o124-v6mr6764650wma.101.1537783923860; Mon, 24 Sep 2018 03:12:03 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-2-33.w90-86.abo.wanadoo.fr. [90.86.1.33]) by smtp.gmail.com with ESMTPSA id o12-v6sm3291728wrj.58.2018.09.24.03.12.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 03:12:03 -0700 (PDT) From: Bartosz Golaszewski To: Michael Turquette , Stephen Boyd , Greg Kroah-Hartman , "Rafael J . Wysocki" , Arend van Spriel , Ulf Hansson , Bjorn Helgaas , Vivek Gautam , Robin Murphy , Joe Perches , Heikki Krogerus , Andrew Morton , Mike Rapoport , Michal Hocko , Al Viro , Jonathan Corbet , Roman Gushchin , Huang Ying , Kees Cook , Bjorn Andersson , Arnd Bergmann , Andy Shevchenko Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v3 1/4] devres: constify p in devm_kfree() Date: Mon, 24 Sep 2018 12:11:47 +0200 Message-Id: <20180924101150.23349-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180924101150.23349-1-brgl@bgdev.pl> References: <20180924101150.23349-1-brgl@bgdev.pl> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org 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 --- 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 Mon Sep 24 10:11:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10612173 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 A21FB157B for ; Mon, 24 Sep 2018 10:12:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9109929ED2 for ; Mon, 24 Sep 2018 10:12:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 850A429EE2; Mon, 24 Sep 2018 10:12:21 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36EC429EE1 for ; Mon, 24 Sep 2018 10:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728549AbeIXQN1 (ORCPT ); Mon, 24 Sep 2018 12:13:27 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53397 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728344AbeIXQNZ (ORCPT ); Mon, 24 Sep 2018 12:13:25 -0400 Received: by mail-wm1-f68.google.com with SMTP id b19-v6so9053907wme.3 for ; Mon, 24 Sep 2018 03:12:06 -0700 (PDT) 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=Ig9mBor6Vwwn4DYl4UdniUpV/rwBF8VdzUTE/e7dEs4=; b=JJRM0KSL00sDd4gsBejDecMytRBu57SOdnHmLSJdvSWRrtQmxoD7GlHievO5p22+XF DIwqPilexuKrnMQxg+x7VKNHaqvrxGOciQVt78pq+IiP/07OKF5DIyOMPySo0wVIbCBk GfuMANULQwzE7RboMFugcqwVjxXaP/J1Fb4sosS8406LgoX7Q7qNxyFCG6bsunDtTDL3 A1TQsZDYpdt0MvfqEavVlMJW4IsQUCvKcdc4lP6i3R+I3WHjN+c7mKVjxSkPlNPYEahT l4IpY393sTVPuYFHvrHY1fAchqjisT8k0qOuQSNAUkVSQgKfk07YMMMaUkaB3MZ4mTx0 pORw== 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=Ig9mBor6Vwwn4DYl4UdniUpV/rwBF8VdzUTE/e7dEs4=; b=UT8evzWrK7F/SjmKc/4CUAClKeSh37nKlCqJPvenScn/bEpnHIex8GH9NDg3bteYGI 5VHKqSodRA/l+TKWs3e9E2gdWpVfOKJXcY17TkITq90EaZoBGzZw//P56RyFWTccSF0x tJUKPGTF4ZCJ8o2zErdXQz/pjufV5G5R3kfEkxkEdDGtjcI9dzi9NBFRxxmKjNtLl9TB DzF5fzkOtOQctYPl5v+fH3Z/1x6MEiv4SubE6EoUU2uFuuS2v7fY4b1dUOGNHF4lKPGx ZCEpPVzrrJaFBq+M2KO2nwZBpfBNFSXA98BvBl6JtSnz10XushL1B3XQNBofWs6PPfk8 SMYQ== X-Gm-Message-State: ABuFfog/QxFfsF0sAGnCBdqhiZOlcwj9D1CPr98H2OeABorznKzcJJKQ dTrhJxgjiZmUIngjYTWegzwPlw== X-Google-Smtp-Source: ACcGV63UZdxzfT1JG65wI1i05x8zgahoA5qW9lU5GZg5qEmKLT2APagXP/h1Z6esoAJFAh0uHQFlYA== X-Received: by 2002:a1c:b20b:: with SMTP id b11-v6mr613454wmf.64.1537783925302; Mon, 24 Sep 2018 03:12:05 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-2-33.w90-86.abo.wanadoo.fr. [90.86.1.33]) by smtp.gmail.com with ESMTPSA id o12-v6sm3291728wrj.58.2018.09.24.03.12.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 03:12:04 -0700 (PDT) From: Bartosz Golaszewski To: Michael Turquette , Stephen Boyd , Greg Kroah-Hartman , "Rafael J . Wysocki" , Arend van Spriel , Ulf Hansson , Bjorn Helgaas , Vivek Gautam , Robin Murphy , Joe Perches , Heikki Krogerus , Andrew Morton , Mike Rapoport , Michal Hocko , Al Viro , Jonathan Corbet , Roman Gushchin , Huang Ying , Kees Cook , Bjorn Andersson , Arnd Bergmann , Andy Shevchenko Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v3 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h Date: Mon, 24 Sep 2018 12:11:48 +0200 Message-Id: <20180924101150.23349-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180924101150.23349-1-brgl@bgdev.pl> References: <20180924101150.23349-1-brgl@bgdev.pl> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org 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 --- 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 Mon Sep 24 10:11:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10612161 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 D98F8157B for ; Mon, 24 Sep 2018 10:12:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C58E529EE1 for ; Mon, 24 Sep 2018 10:12:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B985D29ED2; Mon, 24 Sep 2018 10:12:12 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE44529EE1 for ; Mon, 24 Sep 2018 10:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728626AbeIXQN2 (ORCPT ); Mon, 24 Sep 2018 12:13:28 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39526 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728529AbeIXQN2 (ORCPT ); Mon, 24 Sep 2018 12:13:28 -0400 Received: by mail-wm1-f67.google.com with SMTP id q8-v6so9403502wmq.4 for ; Mon, 24 Sep 2018 03:12:08 -0700 (PDT) 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=XAjBhV4AEAXhQXiXfZCfBofMzbagPKbxDfjukdf0psM=; b=U9CNVgpkzrL4OvueGLRFk8ZILjjyyFHgpudl/5z72bjMk/62AELNp9gA6tX9L7TCcz CRPFzqc/lGBawA+rhlkaGrI8zfUnnxosaYgtsRIzHLK8pRlRhPeUnxrZy8dyTTeRjiWv oog6+Oslhp3r2TLolLk3wAYISd2W7vVOQBA2XGS5LmOw0cnvvXTKe7H22dkjWquxI86e 4jZyrCn5dXpxT33ysfflcye7D5rP14tNbrqRBhTU7+bUeMsrFPYo7RpYHaLIvZibYx9b 6bLh9F4/F3pNAz5uS+3jYGsIqF71x5BPAhtLK4XvqYYUrP3eERMiZOLaDeVZf2VeFnzA SWoA== 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=XAjBhV4AEAXhQXiXfZCfBofMzbagPKbxDfjukdf0psM=; b=MvHnGwFFSw00FY9Tw6xJpgZBqicjJfvPDuMEjJ/Vr+xzRAtlee/uwSiw9Z2oG4DI6U 6nt4+MSdD4k3jCtoiY+EZnEJScBJFt/501ryf3P9PtZo9D8aMuLrR4Fa3s2kkJTV4XZ2 hTN36X09rEMISDSHpGcT8cshdZ+wpfHuYL/H/WofickwO+8mk8SBQE1HMCEd7hwejEzX FNDKpfEsvusRQdRl8Fc8ZR+UB3TXKcnwY8EernH6fwA4nRaqfETzYoOm3WRjNKD9fleP /qsDgF8x2iNBVx3o4YmL4OQ5w20FB73d0wasV0P4CLEX+RosZx8RIFrfFF51yPQXzuBE T1iw== X-Gm-Message-State: APzg51ADTToET0k22SLAOARLFrO0gUoZ22I+h2ZKzuDmmG1bVFhWUVrb mk2uD2IS68bzyxCiOZPS0q8T1A== X-Google-Smtp-Source: ACcGV62+Sgy75fLne3seCROrjfDu6thd6VNFdZQleEdJLCr1Uj8yOtYHIB12h5OQlRf3mCk0DL/+bQ== X-Received: by 2002:a1c:b5d3:: with SMTP id e202-v6mr6487055wmf.23.1537783927188; Mon, 24 Sep 2018 03:12:07 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-2-33.w90-86.abo.wanadoo.fr. [90.86.1.33]) by smtp.gmail.com with ESMTPSA id o12-v6sm3291728wrj.58.2018.09.24.03.12.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 03:12:06 -0700 (PDT) From: Bartosz Golaszewski To: Michael Turquette , Stephen Boyd , Greg Kroah-Hartman , "Rafael J . Wysocki" , Arend van Spriel , Ulf Hansson , Bjorn Helgaas , Vivek Gautam , Robin Murphy , Joe Perches , Heikki Krogerus , Andrew Morton , Mike Rapoport , Michal Hocko , Al Viro , Jonathan Corbet , Roman Gushchin , Huang Ying , Kees Cook , Bjorn Andersson , Arnd Bergmann , Andy Shevchenko Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v3 3/4] devres: provide devm_kstrdup_const() Date: Mon, 24 Sep 2018 12:11:49 +0200 Message-Id: <20180924101150.23349-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180924101150.23349-1-brgl@bgdev.pl> References: <20180924101150.23349-1-brgl@bgdev.pl> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org 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. Also provide a corresponding version of devm_kfree(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Bjorn Andersson Acked-by: Mike Rapoport --- drivers/base/devres.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/device.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/drivers/base/devres.c b/drivers/base/devres.c index 438c91a43508..48185d57bc5b 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. @@ -895,6 +919,20 @@ void devm_kfree(struct device *dev, const void *p) } EXPORT_SYMBOL_GPL(devm_kfree); +/** + * devm_kfree_const - Resource managed conditional kfree + * @dev: device this memory belongs to + * @p: memory to free + * + * Function calls devm_kfree only if @p is not in .rodata section. + */ +void devm_kfree_const(struct device *dev, const void *p) +{ + if (!is_kernel_rodata((unsigned long)p)) + devm_kfree(dev, p); +} +EXPORT_SYMBOL(devm_kfree_const); + /** * devm_kmemdup - Resource-managed kmemdup * @dev: Device this memory belongs to diff --git a/include/linux/device.h b/include/linux/device.h index 33f7cb271fbb..79ccc6eb0975 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -693,7 +693,10 @@ 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, const void *p); +extern void devm_kfree_const(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 Mon Sep 24 10:11:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10612169 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 F054B15A6 for ; Mon, 24 Sep 2018 10:12:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEEF429ED2 for ; Mon, 24 Sep 2018 10:12:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D26E529EE2; Mon, 24 Sep 2018 10:12:18 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7355229ED2 for ; Mon, 24 Sep 2018 10:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728529AbeIXQNa (ORCPT ); Mon, 24 Sep 2018 12:13:30 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44321 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728389AbeIXQN3 (ORCPT ); Mon, 24 Sep 2018 12:13:29 -0400 Received: by mail-wr1-f68.google.com with SMTP id v16-v6so19052199wro.11 for ; Mon, 24 Sep 2018 03:12:09 -0700 (PDT) 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=jLISmJc2dPUxbBj3RDyXz5hdQLm9DxNuC15aZU3ms6g=; b=BDV7axJatr4Cp/LBdA1G+Vka0/jKPXb00CWdvOX431pLfQhTXSlFx6jbCOJK3Ajxor Wl9GQa5xgfkoKGBjNNdbYM3/72d+n77JH9SdjDJkKEPrG+f7+SOp8Zr/0Ki/H9YFJ3eT EoPuOWVQbC044VSDjJDLe9cOXRc5aAoF0MkrNyYqVkOTT/JKGmOdqZ9ZdlB6OK4YUknR okBgcDquosDFY3+hUcLNBsDEK5HH9XJdgjApl2acAeurJHFFd7zl2Z1xzn9YBaaYWHj7 CTPBqInRbHes4J3J2Kd0+c5iyc0t+tnQ1/UHcyKScX2Lo+6njEHfYSxi7cUg2Ol/xTzk pKOw== 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=jLISmJc2dPUxbBj3RDyXz5hdQLm9DxNuC15aZU3ms6g=; b=lDgaZ7Ze0fM7aHHbh0pP/4XAONPsC63cu/7NiXQ4wO6Hsstmziv2HkPqE8rbbS/drH 8IDLgkHDlqnVXrBHzWqm0xJbQmCqEqIr2kkZnYqHfMM+D1Avr8iwJqlayX5TMXY6MCCu xd0ojo3w9ayGwCkR/6qtla1QQALj3LphVbGLK0cLBYKZ3U4QOflWU16X05tEHLIiTBOW WmJG7vFj5O1n1435e5BzF0Bmzb6bGYvwRcC1EJK88F5UV8r3+oqx4zA+xYElZVcuG6eP MH7C8lHblQdW6jx3+1gBXJwlCFu3Xdq+6KLG64jd2U5VGKrBPcw81pBDc1O+dLXF2oSJ 0eBA== X-Gm-Message-State: ABuFfohohVsJa9bSw11e8AqMDHoWiUFlC9Nev1kA71pZdQljpm79FCAr 2wA6cee/YFdnvLGI3WD2pW5ysA== X-Google-Smtp-Source: ACcGV62gtGp+dWxaEzs3KziqR8iPoDl9Yh84dvTqcMksDb6+DjHYohhyApW0IsrPrgXPyHrMJnIwOw== X-Received: by 2002:a5d:5009:: with SMTP id e9-v6mr8199080wrt.18.1537783928856; Mon, 24 Sep 2018 03:12:08 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-2-33.w90-86.abo.wanadoo.fr. [90.86.1.33]) by smtp.gmail.com with ESMTPSA id o12-v6sm3291728wrj.58.2018.09.24.03.12.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 03:12:08 -0700 (PDT) From: Bartosz Golaszewski To: Michael Turquette , Stephen Boyd , Greg Kroah-Hartman , "Rafael J . Wysocki" , Arend van Spriel , Ulf Hansson , Bjorn Helgaas , Vivek Gautam , Robin Murphy , Joe Perches , Heikki Krogerus , Andrew Morton , Mike Rapoport , Michal Hocko , Al Viro , Jonathan Corbet , Roman Gushchin , Huang Ying , Kees Cook , Bjorn Andersson , Arnd Bergmann , Andy Shevchenko Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v3 4/4] clk: pmc-atom: use devm_kstrdup_const() Date: Mon, 24 Sep 2018 12:11:50 +0200 Message-Id: <20180924101150.23349-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180924101150.23349-1-brgl@bgdev.pl> References: <20180924101150.23349-1-brgl@bgdev.pl> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as an example of how to use this new routine to shrink driver code. While we're at it: replace a call to kcalloc() with devm_kcalloc(). Signed-off-by: Bartosz Golaszewski Reviewed-by: Stephen Boyd Reviewed-by: Bjorn Andersson --- drivers/clk/x86/clk-pmc-atom.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/clk/x86/clk-pmc-atom.c b/drivers/clk/x86/clk-pmc-atom.c index d977193842df..239197799ea3 100644 --- a/drivers/clk/x86/clk-pmc-atom.c +++ b/drivers/clk/x86/clk-pmc-atom.c @@ -247,14 +247,6 @@ static void plt_clk_unregister_fixed_rate_loop(struct clk_plt_data *data, plt_clk_unregister_fixed_rate(data->parents[i]); } -static void plt_clk_free_parent_names_loop(const char **parent_names, - unsigned int i) -{ - while (i--) - kfree_const(parent_names[i]); - kfree(parent_names); -} - static void plt_clk_unregister_loop(struct clk_plt_data *data, unsigned int i) { @@ -280,8 +272,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, if (!data->parents) return ERR_PTR(-ENOMEM); - parent_names = kcalloc(nparents, sizeof(*parent_names), - GFP_KERNEL); + parent_names = devm_kcalloc(&pdev->dev, nparents, + sizeof(*parent_names), GFP_KERNEL); if (!parent_names) return ERR_PTR(-ENOMEM); @@ -294,7 +286,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, err = PTR_ERR(data->parents[i]); goto err_unreg; } - parent_names[i] = kstrdup_const(clks[i].name, GFP_KERNEL); + parent_names[i] = devm_kstrdup_const(&pdev->dev, + clks[i].name, GFP_KERNEL); } data->nparents = nparents; @@ -302,7 +295,6 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, err_unreg: plt_clk_unregister_fixed_rate_loop(data, i); - plt_clk_free_parent_names_loop(parent_names, i); return ERR_PTR(err); } @@ -352,8 +344,6 @@ static int plt_clk_probe(struct platform_device *pdev) goto err_drop_mclk; } - plt_clk_free_parent_names_loop(parent_names, data->nparents); - platform_set_drvdata(pdev, data); return 0; @@ -362,7 +352,6 @@ static int plt_clk_probe(struct platform_device *pdev) err_unreg_clk_plt: plt_clk_unregister_loop(data, i); plt_clk_unregister_parents(data); - plt_clk_free_parent_names_loop(parent_names, data->nparents); return err; }