Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752563AbdCQBcd (ORCPT ); Thu, 16 Mar 2017 21:32:33 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:51508 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752178AbdCQBcb (ORCPT ); Thu, 16 Mar 2017 21:32:31 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2617860276 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sboyd@codeaurora.org From: Stephen Boyd To: Mark Brown Cc: linux-kernel@vger.kernel.org Subject: [PATCH] regulator: Mark supply_name const and duplicate it as such Date: Thu, 16 Mar 2017 18:07:14 -0700 Message-Id: <20170317010714.2190-1-sboyd@codeaurora.org> X-Mailer: git-send-email 2.12.0.264.gd6db3f216544 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1684 Lines: 49 The supply_name member of struct regulator can be const as we don't change it in the regulator core. Furthermore, when we copy the supply name we can use kstrdup_const() here to avoid a copy if the name is in the ro data section. Signed-off-by: Stephen Boyd --- drivers/regulator/core.c | 4 ++-- drivers/regulator/internal.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index f20ad0a8fc38..49a0b6a2e237 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1343,7 +1343,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, /* non-fatal */ } } else { - regulator->supply_name = kstrdup(supply_name, GFP_KERNEL); + regulator->supply_name = kstrdup_const(supply_name, GFP_KERNEL); if (regulator->supply_name == NULL) goto overflow_err; } @@ -1799,7 +1799,7 @@ static void _regulator_put(struct regulator *regulator) put_device(&rdev->dev); mutex_unlock(&rdev->mutex); - kfree(regulator->supply_name); + kfree_const(regulator->supply_name); kfree(regulator); module_put(rdev->owner); diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 1dd575b28564..66a8ea0c8386 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -29,7 +29,7 @@ struct regulator { int uA_load; int min_uV; int max_uV; - char *supply_name; + const char *supply_name; struct device_attribute dev_attr; struct regulator_dev *rdev; struct dentry *debugfs; -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project