From patchwork Fri Feb 3 01:41:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9553417 X-Patchwork-Delegate: rjw@sisk.pl 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 2356A60424 for ; Fri, 3 Feb 2017 01:42:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14B24284CE for ; Fri, 3 Feb 2017 01:42:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07AA8284D5; Fri, 3 Feb 2017 01:42:48 +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 D347D284CE for ; Fri, 3 Feb 2017 01:42:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751844AbdBCBmX (ORCPT ); Thu, 2 Feb 2017 20:42:23 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35018 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751823AbdBCBlc (ORCPT ); Thu, 2 Feb 2017 20:41:32 -0500 Received: by mail-pf0-f194.google.com with SMTP id f144so387423pfa.2; Thu, 02 Feb 2017 17:41:32 -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=OKWvq4jpG/HnMZku7HGtjkeB+1AcO/V+AQjkhXB2AF0=; b=QDoYWyHAeja4wMuoXojjRApDEKEcYEHzNRsYpv6kdsVFPV2DDY05sv+Po7uIYBwdKf N3z8tfdy2Z1Ex47XHRsJkLMMOuiNOA45hhsnNTRAu6pmBk8ngMZndCyyeCb/zmSfG2ru 61uHTvcwLrSKeQ1G4KlBBcULpeyAkLEpQFBxMZQchUM38JtfwALqND5YDA/C8bmFMrQ0 55AeJla6uCUx1krcARsElYUXa6/guKgKBni0WcuLg7as7nDrTTX8kVTemrFWNkD4CFNJ xMhdPpoiSpUPSNsTiqwxxFXsahOssFkFJKktf33VJvSbN3hXjFe/Sc2g9/gZ8cOY7UjR apxA== 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=OKWvq4jpG/HnMZku7HGtjkeB+1AcO/V+AQjkhXB2AF0=; b=uO2Bz1MAa0MpF8o0+eYOOlbklyzG5J0k3BT0TjFkNTnwefn3h0vrWVLfVbRO0xXcAG 5aKwL1HGHAyNTYDVHn5DyzuYG1pKBZYTv2uGaCCu0uXhzQx5BStRZTHDTZk41uqwRFeB 6gPxtwb/RIsYWRzC7Rg2hi5h/1q5i3VQHKL3nr9oJtPQ8sZMu9fLzq22uyLasKNvzE51 hAkGlEI1dQTHQyAi8awCQ8I6zI1zExouAZbQ47OlPTslGCHMu01ievbcsrnirhRlXki0 JtAJwI0H6YV2F9y1yzUWRSAa5rDLgflG2O5nASVC/UzaU0L4yiUtjlnCNOEukyPy3l39 3JBA== X-Gm-Message-State: AIkVDXLYiykzh+7nWFhV/vNFeEXWKS2E7J/uLPRvyrgYgd4+90zlsroWapK+O3Y4NarXoA== X-Received: by 10.84.198.3 with SMTP id o3mr17251128pld.170.1486086091509; Thu, 02 Feb 2017 17:41:31 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id n28sm1252929pgd.5.2017.02.02.17.41.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Feb 2017 17:41:31 -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 v5 1/4] device property: allow to constify properties Date: Thu, 2 Feb 2017 17:41:25 -0800 Message-Id: <20170203014128.317-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170203014128.317-1-dmitry.torokhov@gmail.com> References: <20170203014128.317-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. Signed-off-by: Dmitry Torokhov Reviewed-by: Andy Shevchenko --- drivers/base/property.c | 41 +++++++++++++++++++++-------------------- include/linux/property.h | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 43a36d68c3fd..e9fa75645d69 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) @@ -776,7 +776,7 @@ static int pset_copy_entry(struct property_entry *dst, */ static struct property_set *pset_copy_set(const struct property_set *pset) { - const struct property_entry *entry; + struct property_entry *props; struct property_set *p; size_t i, n = 0; @@ -787,14 +787,14 @@ static struct property_set *pset_copy_set(const struct property_set *pset) while (pset->properties[n].name) n++; - p->properties = kcalloc(n + 1, sizeof(*entry), GFP_KERNEL); + p->properties = props = kcalloc(n + 1, sizeof(*props), GFP_KERNEL); if (!p->properties) { kfree(p); return ERR_PTR(-ENOMEM); } for (i = 0; i < n; i++) { - int ret = pset_copy_entry(&p->properties[i], + int ret = pset_copy_entry(&props[i], &pset->properties[i]); if (ret) { pset_free_set(p); @@ -847,7 +847,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 856e50b2140c..d37a4498b3ac 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -242,7 +242,7 @@ struct property_entry { } 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);