From patchwork Mon Aug 27 08:21:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10576607 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 7E9D017DB for ; Mon, 27 Aug 2018 08:21:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B29A2994A for ; Mon, 27 Aug 2018 08:21:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C73E2994B; Mon, 27 Aug 2018 08:21:41 +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 4FA6329807 for ; Mon, 27 Aug 2018 08:21:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B9416B3F8E; Mon, 27 Aug 2018 04:21:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 741156B3F8F; Mon, 27 Aug 2018 04:21:39 -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 5E1CB6B3F90; Mon, 27 Aug 2018 04:21:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f70.google.com (mail-wm0-f70.google.com [74.125.82.70]) by kanga.kvack.org (Postfix) with ESMTP id 01C9C6B3F8E for ; Mon, 27 Aug 2018 04:21:39 -0400 (EDT) Received: by mail-wm0-f70.google.com with SMTP id l4-v6so7122840wme.7 for ; Mon, 27 Aug 2018 01:21:38 -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; bh=fE0L4qS4JAIcIeGVF5WHMr5nRwEMI4xXJIjWAI4oJwo=; b=qC9C6rnOcYR+eIcIQtyLMP2AnNXfml7QzaErJds3OGv1YqcNkYIvqAoxEisRObo36/ irq3cppUNgzE2ApIh7kt1GtNBKAnshqdhndk44CL0JntlwbhN5A8s5rELAx4gGtzgGV8 /Ta9GhU0aGLdDBWQmqdsfro+8JpOfVGHljjYfc8qmr//kHxmsJ0uehBlbWMtSj3VT+Qr rCyzYnnmKJWxWYjTAXgJGVRKU8AL6eR8xUs1O1PhtLHRsdMfkgGCitl9kZq9DTiVQkcE 5AcQC0NTu6tNIdfG/WQMtCkcqPWYvMy41ME+7HgvXopAT26Va8fRqT4PPEdB9+8D+jmj 61cg== X-Gm-Message-State: APzg51CNwryQsoWBdD/4mfJy/jVWbxD8plyI+lEBFQmGXyl56b/+kjjd +oNVtHD8nz5kgzoxdfECMOQPyvFE9lMQSdXrcF4mvDbC8RXL2OaMxYQNMiv3B5ZJOEy2NkZNX/t sueP5pBRTi42zSBK/SaL8p0HxaZVM8yjdhJWp3riIzN9TD+RgBTXtBCUBIcM9zTz0b7KhViuI+X ieOFkBawYJjE1pYzXP4gKnW9Ey0Dj0s4RLibYKQRX1UgyCFz7EPnWHD6tMTpDdZEnhe2cxui8Ua ih5opqnVqazcgdemebz4jX2lIGKyVZEsYv0fQ++vU3KIfzPJQByiiOSsDdfJ518ODGmTjo/9wjY VIwY5qTMsmv5WYSp5QyvIE2jikYGNzOTQXnDHQpiUmN8Q6KjzI9clrJIFZR9XAnITCasnKw9HUm t X-Received: by 2002:adf:b2b5:: with SMTP id g50-v6mr7541268wrd.218.1535358098490; Mon, 27 Aug 2018 01:21:38 -0700 (PDT) X-Received: by 2002:adf:b2b5:: with SMTP id g50-v6mr7541241wrd.218.1535358097697; Mon, 27 Aug 2018 01:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535358097; cv=none; d=google.com; s=arc-20160816; b=MLcpwCYd45wiHLqcEmLsKVvnEhoRPQ1wfZ1afZOgqKNjjGH+I5cF2In9NjTKuFvEkM GsI7nYdrt2yDQL+hQXPstz/Nrm3yktLKX6ltEt4luSyUEmU91TZIL4drwI9rcahR9cTy /jswuaApdtp5twitWIUOb9n2hmc6mTn6CIOPoSihskscERLqLRnHEEPyynwC2HLug0WZ g/oPMfX2ojhYpvT5gb8yx37P7mjh0+3z1cDMx+vzmHF4tluE0o4tH3srGoowHuA5l/7g dyY82T/p+K2oplLUy9QDfSviaKju8I7v8HpgY35aQ21yYNonzOwJzlJJekFdIJ7W0GfN sZkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=fE0L4qS4JAIcIeGVF5WHMr5nRwEMI4xXJIjWAI4oJwo=; b=Il2lVL2WGJ6xsvLfyA/tuHa4L7b4fNh5vrqpyPp5Z+Sb2nHuZkjy01Zek85ot0n1tn zNeAGK02JKNB22lC6lRnHQM9B+aeAMvyK2A7hRoW6bkJmOR+mluRw7QlviY5bZIbC8Kb mXg/wHy1qlKkM/6RVewk2P8nk3vo+1pCcdIAWZR9wPw+dbXhmT6UXeguHn4hhJvJSLnZ 1Ablnkap0b8943VMJawmXw27gt4J6FYGN63cjEAyMM+OqoP2afhm+JK7CFhXq/vOdwOi NWRGCX2fzeNrAd4AfCr2rRPp5JHF8SlBGIC8JYdI6WbTvDywYd4qQQ8tI3y9CTUjwE8h N61Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=bAKJB+6Z; 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 u3-v6sor4857298wrw.12.2018.08.27.01.21.37 for (Google Transport Security); Mon, 27 Aug 2018 01:21:37 -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=bAKJB+6Z; 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; bh=fE0L4qS4JAIcIeGVF5WHMr5nRwEMI4xXJIjWAI4oJwo=; b=bAKJB+6ZeJaBDy0gRuAYKSpwqe8e7mxVfGS3uGmJ9XEnoHTA/g9z+ibiHWvvAt5We9 A0HA9PUmAlPtA4SoAn9CMXYZD2S/tgSqpZbGQzoH7/Q8PcxfnKZOXpnac9lU2GXqhCfW F7xIPrhcZ9D3e65SPVHmlwyG+JCuoxkT+rPeTF4x9XsOAgv6gyapsKrMWSjgWSIlRpBQ 0ddGzn3PSS0XCslxGwK0hDuoi/7RpAiQPH8/6w7ymGN/6MQI39yaIU7sm5h/XHtg9nUn /ejm45JtXTw5Ex0ntGhVoqQRbNsSa/tNjBpqMV/kkYQ/sQe0b2G6WQ4iJa/QgH89UOYp nUAw== X-Google-Smtp-Source: ANB0VdYVp6PH5lkGi93mUyekgo0jMNaTlitZiC7F1f47jSxuq+FzHEVKpHdnWQCwlydgRgnKfRA7nw== X-Received: by 2002:adf:b583:: with SMTP id c3-v6mr7953572wre.79.1535358097344; Mon, 27 Aug 2018 01:21:37 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-34-229.w90-86.abo.wanadoo.fr. [90.86.153.229]) by smtp.gmail.com with ESMTPSA id b144-v6sm15402309wmd.23.2018.08.27.01.21.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Aug 2018 01:21:36 -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 Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH 1/2] devres: provide devm_kstrdup_const() Date: Mon, 27 Aug 2018 10:21:00 +0200 Message-Id: <20180827082101.5036-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 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. Also provide a corresponding version of devm_kfree(). Signed-off-by: Bartosz Golaszewski --- include/linux/device.h | 2 ++ mm/util.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index 8f882549edee..f8f5982d26b2 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -693,7 +693,9 @@ 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_const(struct device *dev, void *p); extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; +extern 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); diff --git a/mm/util.c b/mm/util.c index d2890a407332..6d1f41b5775e 100644 --- a/mm/util.c +++ b/mm/util.c @@ -39,6 +39,20 @@ void kfree_const(const void *x) } EXPORT_SYMBOL(kfree_const); +/** + * 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, void *p) +{ + if (!is_kernel_rodata((unsigned long)p)) + devm_kfree(dev, p); +} +EXPORT_SYMBOL(devm_kfree_const); + /** * kstrdup - allocate space for and copy an existing string * @s: the string to duplicate @@ -78,6 +92,27 @@ const char *kstrdup_const(const char *s, gfp_t gfp) } EXPORT_SYMBOL(kstrdup_const); +/** + * 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 + * + * Function returns source string if it is in .rodata section otherwise it + * fallbacks to devm_kstrdup. + * + * Strings allocated by devm_kstrdup_const will be automatically freed when + * the associated device is detached. + */ +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); + /** * kstrndup - allocate space for and copy an existing string * @s: the string to duplicate From patchwork Mon Aug 27 08:21:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 10576609 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 673D51390 for ; Mon, 27 Aug 2018 08:21:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 554B9294E6 for ; Mon, 27 Aug 2018 08:21:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48A7A29958; Mon, 27 Aug 2018 08:21:43 +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 D14B929944 for ; Mon, 27 Aug 2018 08:21:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E23766B3F8F; Mon, 27 Aug 2018 04:21:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D5CFA6B3F90; Mon, 27 Aug 2018 04:21:40 -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 C299E6B3F91; Mon, 27 Aug 2018 04:21:40 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by kanga.kvack.org (Postfix) with ESMTP id 6061E6B3F8F for ; Mon, 27 Aug 2018 04:21:40 -0400 (EDT) Received: by mail-wr1-f72.google.com with SMTP id q18-v6so14252850wrr.12 for ; Mon, 27 Aug 2018 01:21:40 -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=1rAADFiEcrgAP/MWUhEq9f5JToaQRAnXC+gfalAjE3k=; b=JbrUcv2ncnNJFBPK6No4JYi8c4HnOnxmW9JI0pWN7eEjh1q2lfaLprppbIRZLMC+GX rgUhpURX4N5Bvt3wmf30P+9dKiJAf1Yqp73glsoQzrsJHMjRXg5I/4gu15dsVpu/vm8S lITaYzTxPUPMD7oVwqix1c8UaSrZSc4QFescL/Qkq1FmmFRDhCd4hm2QJCaucPnsyLv4 L9nGZW/igDBL6J3VfW9wEornda2EQKNtw1TQOVt2EPQpVMtH79MnDCAx0TTFVfgbPY3j p/hnxMcYQLCWoey4Fj6FNfNvgZhxf00QXbtPD4lAiF3ySCCPltPujy00h0HunuJ8UZ2d 71Lw== X-Gm-Message-State: APzg51CKIXoWS4euD8RFon4A1R+AxnwiMHcjUHI7PDFzy+jn82rzhUmV Jk67xfkMt4u/8X464BPG+3zED12RKsibQ4Z8wGM3ZaeIDit6t0nAZYTlXY51BQNForJGpoewnc/ OUHZ5bnfNHEwOL/EyIqze5HG8c9gm0rOzCvsACwc5QvOYG+qvnQ+S31sP+mFySSBqGQDbmY7ka0 WLmuNgWIyLUazSOpLN008FnZCv+5Bd5mLrUeL9FwudrV3PqzzpBMnlguOROecSuQS5N/BWFNqQF UlVUfnfKbTdpyVJu0yQhRh3frAbtaJdgAYWfSIvi0Mz6ARKFOxmElXRd2WNZdsr7MqdKZVd6Vbq Dt+LdU8oCa2EVZSNddiUNIz0PH8+C5n0UmcQYxl1cnxt8RCVmhmC6HmOrMXtTo83RMTjrPdUgE1 b X-Received: by 2002:a5d:55ca:: with SMTP id i10-v6mr7666556wrw.38.1535358099791; Mon, 27 Aug 2018 01:21:39 -0700 (PDT) X-Received: by 2002:a5d:55ca:: with SMTP id i10-v6mr7666521wrw.38.1535358099054; Mon, 27 Aug 2018 01:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535358099; cv=none; d=google.com; s=arc-20160816; b=wK/rNWPnf5hm27kefqRmLClb9Lomt/du/NTRmAbRnBGmRtH/EOOrcgwcV1ubx5bbb9 jHMSEzvjYiwCzS3Umo+tSnaJBUJPs4BpEtFKcQzicECt+dPnmM4wLg8u5Ft6vcfPMGCR 9r9dRi61tzDMLMYeTqvP84NdKCed62IcGqVklkvx290uJRpWnqhnavHgZlMBNEr012OY Qbnk45E7DlyXw6M3ZYSpyY+GNTKb+TjjksHDd7xyTdzv7boorHUQWJfZNVevfrHXwis2 lYax6TyDfXUCDFs/D8sthrDE2hPxtZbhOCv89jQt6+gRMB3BpE0l1hNCZF89W41HlPkv WzIA== 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:arc-authentication-results; bh=1rAADFiEcrgAP/MWUhEq9f5JToaQRAnXC+gfalAjE3k=; b=i2bRZxJQhGN5G3JFBhluqlsvfQF4c3MxcOqtFqZP4r3KU6N0dAwG8v9sm8a0Lk+miM ILnjGZtkt7Rx5wEeYah0vYRnsNPypGBgASyDaverZd1L4P6F6IzImBaIYQHr5xGI03FC LsgPhzSdEOi9FqK4zOFQHXbEhqiBcCk3UyPkn/WjLYpyoeEzShqFgdPHmix7t4IU4FU8 hly0UG8y+K8gQBqEP1SDvdO5xj183GlL/k3oeokRsoQ4EGxyxn92Dgm5q7UCKyApg9be npLQ4wmw5OKns/Ghg2qErnaqFlaurZiAAxg/k1PIdfyubbpapPzPiQdubP7/HX8q1yx6 j4qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=kSA+bUIP; 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 w14-v6sor4922290wrr.11.2018.08.27.01.21.38 for (Google Transport Security); Mon, 27 Aug 2018 01:21:39 -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=kSA+bUIP; 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=1rAADFiEcrgAP/MWUhEq9f5JToaQRAnXC+gfalAjE3k=; b=kSA+bUIPd6Kz4LJRN6u2xwlR03fuwZZ0LXX7sehdNQwu33qwmRrZyno38C8pUoZHfw JeAER5jFwAR2r3pHlT72urG7rxpz27ZVMgsenvJk3vF9hJLAVE90j5/OlXAZupc+s3p+ tehRe76aLGrVhr/oZL/mdKoNuNCap/PIrVVcc4VZbZQ26r/dZxUekiJsXE67ET5wIOrG rPaamujN3EOrUS4t/N5dUJLHG7g8pvmO2+8HzrU+Wug2Vqt4WEo9hKOJjigQN8Uv+5Ny zc/DapaghZbfFfpIK7LLFtW/JQNpCfpK1mwPw+wKyo1A/S1BJsrMHK7bgBhmw57NPf9y tqhA== X-Google-Smtp-Source: ANB0Vda/wBMEVgVNlmupmmRuXOmBZUZx3pISV5xfHqiKv7wtutnfRK5d+xufRmR7miQhQbIZvZxuAw== X-Received: by 2002:adf:f24e:: with SMTP id b14-v6mr7420220wrp.184.1535358098735; Mon, 27 Aug 2018 01:21:38 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-34-229.w90-86.abo.wanadoo.fr. [90.86.153.229]) by smtp.gmail.com with ESMTPSA id b144-v6sm15402309wmd.23.2018.08.27.01.21.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Aug 2018 01:21:38 -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 Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Bartosz Golaszewski Subject: [PATCH 2/2] clk: pmc-atom: use devm_kstrdup_const() Date: Mon, 27 Aug 2018 10:21:01 +0200 Message-Id: <20180827082101.5036-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180827082101.5036-1-brgl@bgdev.pl> References: <20180827082101.5036-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 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 --- 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; }