From patchwork Tue Aug 28 09:33:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10578099 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 ADF10920 for ; Tue, 28 Aug 2018 09:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F781299F4 for ; Tue, 28 Aug 2018 09:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9294429A0C; Tue, 28 Aug 2018 09:41:44 +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 4864C299F4 for ; Tue, 28 Aug 2018 09:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727210AbeH1Ncb (ORCPT ); Tue, 28 Aug 2018 09:32:31 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35597 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727130AbeH1Ncb (ORCPT ); Tue, 28 Aug 2018 09:32:31 -0400 Received: by mail-wm0-f67.google.com with SMTP id o18-v6so1298219wmc.0 for ; Tue, 28 Aug 2018 02:41:41 -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=SVWcFbk/dVzlsS+UwHvhPxvTnIJPJG8C6MWyhlzaJP4=; b=TjY7XD59PXtSvVirztIUG/IzfuDVWIiYSDoXxS4NQ4F2s7v5QZzehTI9rlcKQKQmHC S7Wfo/sISESMCfGCmTz8pBDEpoKRlEvMSySpNcKszz/mSeCD6r3ZYQqh7NS42cCUrTUl ohCflbE1aFg6Cg8i4w7T4tUE1hRO4ML0HDDYDXlYX3s/sM/60rqYtpraEcXbn7VFpFsI Rf13u+/Ix6L/8VCcE26REBhIMzh4gODasHflNG5XY4jsGkCfFaneUEaxxPeL1JAmVr33 4agPt2IlxFibmgO36O4hLogKoEqwoSfDEogM+joTQ4uEDhYEWBHeY58XBOHgpQLO+h8I Ngjw== 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=SVWcFbk/dVzlsS+UwHvhPxvTnIJPJG8C6MWyhlzaJP4=; b=ArBIyFRl96pNZ3NrRl97io0qr4Ncdtc5H2WeZy8iGV0yA3Vo3zkEYjRzcL2w3pUiEx utusUYsOCTFwzFiJ8kzFxYC1WQREqdSPbebkjxg4DqcBFvciuE83VvArhw442CPBI1VC T9IaQMqpUm8gMVT2LhTM/XCcyzaxQIRh+oU9GIw/K2BjdgWKJmPpZI7lgArg+hEHpBtl 4VDkT6k1DAh2N75ARYIEV1Px2KiZGeizhiAHJ88O0B5okTKabGiuJVpepeyI6a+0vRm6 I0jqm3nvVdSd7qxTU+pp9vZud0BWAalg+xwQ1W/RjE8UjO6jVwfT2Hq0BJ0gUnfh5A1X yGvA== X-Gm-Message-State: APzg51AVUcEfFYYwgMiCeH2cVxuRDZjLSJUWIKApRzNNN1u3LfKci/Wd P7DEyg3UfJosEgUKu/aIRakFJA== X-Google-Smtp-Source: ANB0VdaV9Pzpww2Wl5G6NP9NsWTUDI9DTePHGQQs1BV4TSeNoZ3PsHOAKQ3DK7ioV0EeP/SgV6txyQ== X-Received: by 2002:a1c:b213:: with SMTP id b19-v6mr759080wmf.141.1535448846439; Tue, 28 Aug 2018 02:34:06 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id l18-v6sm952276wru.75.2018.08.28.02.34.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 02:34:05 -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 Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v2 1/4] devres: constify p in devm_kfree() Date: Tue, 28 Aug 2018 11:33:29 +0200 Message-Id: <20180828093332.20674-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180828093332.20674-1-brgl@bgdev.pl> References: <20180828093332.20674-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 Tue Aug 28 09:33:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10578097 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 01FF317DB for ; Tue, 28 Aug 2018 09:41:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7868299FC for ; Tue, 28 Aug 2018 09:41:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D948929A16; Tue, 28 Aug 2018 09:41: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=-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 80479299FC for ; Tue, 28 Aug 2018 09:41:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727169AbeH1Nc2 (ORCPT ); Tue, 28 Aug 2018 09:32:28 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46672 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727130AbeH1Nc2 (ORCPT ); Tue, 28 Aug 2018 09:32:28 -0400 Received: by mail-wr1-f66.google.com with SMTP id a108-v6so905835wrc.13 for ; Tue, 28 Aug 2018 02:41:39 -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=wc9ZRwnUmb5rXGt9YW/Z3OT0r34lfcDOfLS8ZydfUMY=; b=MME6CIbn6ztirIfcMA3UHlZmo1USCfNk6oYrqrfS2kcBjaNSlBGu0Xt3IwJZJhOBa4 zRIVln4bKyOO9n7wPDACSj85rW1EivMdt4i794d5x79jKqT8lqvxRhLlvILxHCDAOGbD seIfVj33o/l6LK9f+eDElZyrX6Z+uhE83lFQTN98edjMRs5CpMwoYxwH6rks8zSFzkdp q+1pL9rlXPsXqmQHC/m1wvlrWWZCscU6mCX/Ru8R5B1aMJxPj1b2QDe4SUWDRE0ncTg7 r1hGif/HO0HXvVRQzxgJOlmQeSasPabVm9nYQ529cNM+/kyaUmuiTT+l8ZFQ9UGnEErd C9yg== 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=wc9ZRwnUmb5rXGt9YW/Z3OT0r34lfcDOfLS8ZydfUMY=; b=rSgQ+MI3kN6fGxldDTxBtnzh3QmajFY6TTZwepcpwp12mh0Phlbh16FnBiNEOhic3m CbjTXUIwI6wdzWpTs3MqqSIsDftdKbznuXzJPyzuWex50ZU4TRowIWJGhy8HdpJnaoRE EbZJapLOOKWXwHgUWbl47BY+h3OFRWBz27HyOrfjEo3Zv3lMLm4rBriPTC6/67aslA/D c7cO0WlZC+NhJf7jzlS186F+X+nJiCCWA/thh88zo9FwvCMKLnMNu5CPrXRLwoHBGNyf H/9P3im26o1FtbxwID7LTGktanTvZJE53eXnTd9poa1I77TsyRLkm2aQy/V3/8JP4mVq s1tw== X-Gm-Message-State: APzg51Cc0toBDdf0A6+fgVsbIIY1Jk9Dzss5aXAGO8aZlhWAMwY0lasA rzTnsTXgMiC0W4NSjskx/ewP1A== X-Google-Smtp-Source: ANB0VdYZg1uzJ+5+eFWd2GzaecxTUS0AzdL/Zfb2QSzLa7FMQgAFFXWWu6LyRuwDUGxRbdwq6jNxzw== X-Received: by 2002:adf:f8ca:: with SMTP id f10-v6mr568901wrq.237.1535448848093; Tue, 28 Aug 2018 02:34:08 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id l18-v6sm952276wru.75.2018.08.28.02.34.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 02:34:07 -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 Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v2 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h Date: Tue, 28 Aug 2018 11:33:30 +0200 Message-Id: <20180828093332.20674-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180828093332.20674-1-brgl@bgdev.pl> References: <20180828093332.20674-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 --- 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 d2890a407332..41e9892a50ce 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 Tue Aug 28 09:33:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10578101 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 AB099920 for ; Tue, 28 Aug 2018 09:42:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BF0329A0C for ; Tue, 28 Aug 2018 09:42:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E51B29A22; Tue, 28 Aug 2018 09:42:50 +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 1C18229A0C for ; Tue, 28 Aug 2018 09:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727238AbeH1Ndi (ORCPT ); Tue, 28 Aug 2018 09:33:38 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35703 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbeH1Ndh (ORCPT ); Tue, 28 Aug 2018 09:33:37 -0400 Received: by mail-wr1-f65.google.com with SMTP id j26-v6so938356wre.2 for ; Tue, 28 Aug 2018 02:42:48 -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=ZhPS8aKWZHYYGJDbC8vwHCt0WY7YA5vftpevadBx97w=; b=K7DgoVj8B2c94KzxsFLciUUUVbJs9GG+54y9l44xJv0cIGKEsWtmJ6asfgtAuJRNWG 3YWTqiKNWfRuzi4MGrLExpWGQh33pnpPC31fZLOE1iAYaZnvNBt/3EJXVAqNj7ZSE+GI BMJhuQNbkhunybgsu80wI2MVHZF+0+S2fKypURC6G8Pc77I+SuMexD717Ca3+aF+LLbe UzJnEY249o+9lwmLaJUX6IZQ3YbgBPFpZpqVHYRbpKuZno3BH9GupI4N9Roz4FVRGDCH 96bpEf6CsVsmyV6piYYOMmj0WwEH7xTECiwsKNNBE6PoyKyKGeFQ9Ba7YdipTSodR1f+ fs9w== 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=ZhPS8aKWZHYYGJDbC8vwHCt0WY7YA5vftpevadBx97w=; b=b+aViKQ6D0nbbKO2Ge1oT6F5Nf4aGnxVZI8mW0AXPic89pSWue0nLdSgXIPeLm2gWE w9GIHt79hNPE8dTHhuUbhDygI9agOt4LWva4i9JtFIOa5YYM9cxwTwgQfc12N9DvEflb 3p55lwWCYb8AKl4u+Ws2b4SlM2FEjTDEqB+dT74LNS95gj2HvHsodD5lXeHoXluBnkms SwV9pdN3iXyhVkcAlqN8F3vND81sbMqaAJZ+m/oauulz6fTd0RSwzjOg+2dxpZ8WlwKw +7vnQscW0mozlrvGhV2pvdgLBvPuZzMd2AvI1yunHaVym1vgUXwDROvqAYxu7uW389Z8 OMnA== X-Gm-Message-State: APzg51D6V+tpW5gJFkPLvwtuVCdISQD8fnuW0ovG2vHOrBpDDPGgBx15 3qoZFzQ5UDLtMi0PEhSoYI4Vrw== X-Google-Smtp-Source: ANB0VdazQ1b4GJa2MqkcHdXAY4E48XRwkQi/Vh5haOo3iQRppCTAdopcVEtiX1xS13EEr5bEkgPC0A== X-Received: by 2002:adf:e8c1:: with SMTP id k1-v6mr539276wrn.43.1535448849697; Tue, 28 Aug 2018 02:34:09 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id l18-v6sm952276wru.75.2018.08.28.02.34.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 02:34:09 -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 Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v2 3/4] devres: provide devm_kstrdup_const() Date: Tue, 28 Aug 2018 11:33:31 +0200 Message-Id: <20180828093332.20674-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180828093332.20674-1-brgl@bgdev.pl> References: <20180828093332.20674-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 --- 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 Tue Aug 28 09:33:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10578103 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 B859A920 for ; Tue, 28 Aug 2018 09:43:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7EB82910D for ; Tue, 28 Aug 2018 09:43:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 980C4293BB; Tue, 28 Aug 2018 09:43:33 +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 43CBB2910D for ; Tue, 28 Aug 2018 09:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727201AbeH1NeV (ORCPT ); Tue, 28 Aug 2018 09:34:21 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41371 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727162AbeH1NeV (ORCPT ); Tue, 28 Aug 2018 09:34:21 -0400 Received: by mail-wr1-f65.google.com with SMTP id z96-v6so929533wrb.8 for ; Tue, 28 Aug 2018 02:43:31 -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=1rAADFiEcrgAP/MWUhEq9f5JToaQRAnXC+gfalAjE3k=; b=p//iCCA1MuEaI2HpuhoGbJeHcq2jmfgPJ3XDrG/O5LZF3RXf2wsubecp6Goz7f0o79 LzT65i1lmWoaar1tB5UxTxjHYLeLVHrvQscb6ydeLJHCsQEC69i39aaxHAOKVE1CKahY 0m9Ms8Rx7z5+D6L0OSVn9vhev1b0VzkzfM2hrtrjE+pygIscDuYgdSobWncG3TQ7++De sD6EF5qddYdMx2C+2m+idpSPuNykz0yd5T2H8HNxVmT7wG1hwYOhg8Dyg+E1NitcTEm1 xEWToxnbd0MTBOykkCMbKgEEowFIq/mwptYz6+dx0HFbepSNxia95yLEO1YoSRRJiJ0/ KiIg== 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=1rAADFiEcrgAP/MWUhEq9f5JToaQRAnXC+gfalAjE3k=; b=f/eVuye3/xuAlXQhG0j74/TSiisc+4HqImSyYHCkklovdO+8VHpXVL8FVdQOBP3sVu Yk82bPv62kgWNT9KlgbrszZL15mpwJh9CnaWoJL/wnjoiTD8QbqJ6u1dKyaQynBPgdK+ EDfH9czpq9FSsn9H/y7TtE1P6mK03IR0wvhtWxAPGY8bgN3j2DxqUTFamtXYpAvZ3357 qR6U4JuOhbyE9AfLCzTT8K41DAUSvAgbhiSXaS/8UTLuGLWo8l4dUVIuQH9N3dbM3A2Y Kgvsr/+R7IF+dde5xbpEGs1m7zx5RU6QRB3Lj+OZafb0Xnm9tBQFM1vHtYPz4rw6Q3ZB 3QHQ== X-Gm-Message-State: APzg51AcsQ6gI0C8cwgGU4KpPgWk7cx6u5pM6etWoegQqLnJJzHhEVq6 mUnbN/UhyyLEdgoBIOu4MHFddg== X-Google-Smtp-Source: ANB0Vdb1z1itApQb6iLVseTRPyo4shStOLvpCOq0LLmwi14Xk+YVt9l+6hKfzi1quea3dB05Pl4LFQ== X-Received: by 2002:adf:9d1c:: with SMTP id k28-v6mr604790wre.104.1535448851396; Tue, 28 Aug 2018 02:34:11 -0700 (PDT) Received: from brgl-bgdev.home ([2a01:cb1d:af:5b00:e837:b8d5:48c1:571b]) by smtp.gmail.com with ESMTPSA id l18-v6sm952276wru.75.2018.08.28.02.34.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Aug 2018 02:34:10 -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 Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const() Date: Tue, 28 Aug 2018 11:33:32 +0200 Message-Id: <20180828093332.20674-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180828093332.20674-1-brgl@bgdev.pl> References: <20180828093332.20674-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 08ef69945ffb..daa2192e6568 100644 --- a/drivers/clk/x86/clk-pmc-atom.c +++ b/drivers/clk/x86/clk-pmc-atom.c @@ -253,14 +253,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) { @@ -286,8 +278,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); @@ -300,7 +292,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; @@ -308,7 +301,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); } @@ -351,15 +343,12 @@ static int plt_clk_probe(struct platform_device *pdev) goto err_unreg_clk_plt; } - plt_clk_free_parent_names_loop(parent_names, data->nparents); - platform_set_drvdata(pdev, data); return 0; 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; }