From patchwork Wed Feb 1 02:11:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9548863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 121EC60416 for ; Wed, 1 Feb 2017 02:12:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01ED52840B for ; Wed, 1 Feb 2017 02:12:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB0A828410; Wed, 1 Feb 2017 02:12:22 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 7ED422840B for ; Wed, 1 Feb 2017 02:12:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751289AbdBACMJ (ORCPT ); Tue, 31 Jan 2017 21:12:09 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36319 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751014AbdBACLf (ORCPT ); Tue, 31 Jan 2017 21:11:35 -0500 Received: by mail-pg0-f65.google.com with SMTP id 75so32625384pgf.3; Tue, 31 Jan 2017 18:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fczHgYNWd2B260O/2kWDYXiJJ+/LrXaGV/JHhz36P0E=; b=CnLHKqgJEOTfaMxNnyenvqHI6oNubh0+EKWXeDgOY9qfXmbCYFVQR9ngiXHm92RG3u Vy0HwOvrJ5j9QFHq3swJBT5wvR2qa4mp7VJi3YSSm+Gd3MOXWwLJupEnsYAh8bSV7znA qiHY7FXRtj8EBJOTMCHlOxrZiOp29kwgELfQQDu+hpgVGOd5e8KhjSKHbdkIZ6xalQBm w5AMcf0f/ROaknrCEG+k1zgsKVX1mJoqMxtfvzSG8KIs97wqrq8Bk2jttlaGod0fnG+S YAnAeq+xz2cxvOhFndK6pLbg0v9HyJAskL6gFMRTRbw9RG8xCAyPufpH54UIEkmKwbqV koTA== 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=fczHgYNWd2B260O/2kWDYXiJJ+/LrXaGV/JHhz36P0E=; b=X1ON7i4Y6yBpb7edTzUvlgjajJFtKEIlsko/pvi64gTFGMPlCaELlbLLMwkBmEYunc SHsvgoNRqtJTxU9BxeEqwyEhLajC1stiRLHY+MnTQwpKOjPnIvSnO4f/YR/4wQfcFckA KUBIDVoJk5hEaaXLkATacAReAw2CYhNSBGJdzm6fhahmxInO5nKkyKCs7CXM5Vk5w8bF iGdgiW3TMHa/nZcaUWl8D/rt96jwDVZk9FBH7DoFhTSQ4Q0R/gj5/2DJswkuAOAvjqy/ 3lmQ9HNWL2ySBT+Po73QFyD9eBQbBTNJV6Pt3xdHPf4X6mmSbB5Ct0JGSTmuXyN4GYQ8 nIaw== X-Gm-Message-State: AIkVDXKqQ0IDGbmeBPsj8VPJ6OJc+lCe3HUpu9FwU6CX9U2Ic5nHd22kSLgmF9KSX0d/zw== X-Received: by 10.99.1.87 with SMTP id 84mr600257pgb.142.1485915094586; Tue, 31 Jan 2017 18:11:34 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id b66sm44526875pgc.20.2017.01.31.18.11.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jan 2017 18:11:34 -0800 (PST) From: Dmitry Torokhov To: "Rafael J. Wysocki" Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko , Mika Westerberg , Hans de Goede , Wolfram Sang Subject: [PATCH v2 2/4] device property: allow to constify properties Date: Tue, 31 Jan 2017 18:11:28 -0800 Message-Id: <20170201021130.20586-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170201021130.20586-1-dmitry.torokhov@gmail.com> References: <20170201021130.20586-1-dmitry.torokhov@gmail.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is no reason why statically defined properties should be modifiable, so let's make device_add_properties() and the rest of pset_*() functions to take const pointers to properties. This will allow us to mark properties as const/__initconst at definition sites. Reviewed-by: Mika Westerberg Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov --- drivers/base/property.c | 35 ++++++++++++++++++----------------- include/linux/property.h | 2 +- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 934845fc72e5..edc09854520b 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -21,7 +21,7 @@ struct property_set { struct fwnode_handle fwnode; - struct property_entry *properties; + const struct property_entry *properties; }; static inline bool is_pset_node(struct fwnode_handle *fwnode) @@ -35,10 +35,10 @@ static inline struct property_set *to_pset_node(struct fwnode_handle *fwnode) container_of(fwnode, struct property_set, fwnode) : NULL; } -static struct property_entry *pset_prop_get(struct property_set *pset, - const char *name) +static const struct property_entry *pset_prop_get(struct property_set *pset, + const char *name) { - struct property_entry *prop; + const struct property_entry *prop; if (!pset || !pset->properties) return NULL; @@ -50,11 +50,11 @@ static struct property_entry *pset_prop_get(struct property_set *pset, return NULL; } -static void *pset_prop_find(struct property_set *pset, const char *propname, - size_t length) +static const void *pset_prop_find(struct property_set *pset, + const char *propname, size_t length) { - struct property_entry *prop; - void *pointer; + const struct property_entry *prop; + const void *pointer; prop = pset_prop_get(pset, propname); if (!prop) @@ -74,7 +74,7 @@ static int pset_prop_read_u8_array(struct property_set *pset, const char *propname, u8 *values, size_t nval) { - void *pointer; + const void *pointer; size_t length = nval * sizeof(*values); pointer = pset_prop_find(pset, propname, length); @@ -89,7 +89,7 @@ static int pset_prop_read_u16_array(struct property_set *pset, const char *propname, u16 *values, size_t nval) { - void *pointer; + const void *pointer; size_t length = nval * sizeof(*values); pointer = pset_prop_find(pset, propname, length); @@ -104,7 +104,7 @@ static int pset_prop_read_u32_array(struct property_set *pset, const char *propname, u32 *values, size_t nval) { - void *pointer; + const void *pointer; size_t length = nval * sizeof(*values); pointer = pset_prop_find(pset, propname, length); @@ -119,7 +119,7 @@ static int pset_prop_read_u64_array(struct property_set *pset, const char *propname, u64 *values, size_t nval) { - void *pointer; + const void *pointer; size_t length = nval * sizeof(*values); pointer = pset_prop_find(pset, propname, length); @@ -133,7 +133,7 @@ static int pset_prop_read_u64_array(struct property_set *pset, static int pset_prop_count_elems_of_size(struct property_set *pset, const char *propname, size_t length) { - struct property_entry *prop; + const struct property_entry *prop; prop = pset_prop_get(pset, propname); if (!prop) @@ -146,7 +146,7 @@ static int pset_prop_read_string_array(struct property_set *pset, const char *propname, const char **strings, size_t nval) { - void *pointer; + const void *pointer; size_t length = nval * sizeof(*strings); pointer = pset_prop_find(pset, propname, length); @@ -160,8 +160,8 @@ static int pset_prop_read_string_array(struct property_set *pset, static int pset_prop_read_string(struct property_set *pset, const char *propname, const char **strings) { - struct property_entry *prop; - const char **pointer; + const struct property_entry *prop; + const char * const *pointer; prop = pset_prop_get(pset, propname); if (!prop) @@ -880,7 +880,8 @@ EXPORT_SYMBOL_GPL(device_remove_properties); * @dev as its secondary firmware node. The function takes a copy of * @properties. */ -int device_add_properties(struct device *dev, struct property_entry *properties) +int device_add_properties(struct device *dev, + const struct property_entry *properties) { struct property_set *p, pset; diff --git a/include/linux/property.h b/include/linux/property.h index 48f154ae7e99..5746e9927016 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -247,7 +247,7 @@ property_entries_dup(const struct property_entry *properties); void property_entries_free(const struct property_entry *properties); int device_add_properties(struct device *dev, - struct property_entry *properties); + const struct property_entry *properties); void device_remove_properties(struct device *dev); bool device_dma_supported(struct device *dev);