Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1481261
| Path | csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Richard Fitzgerald <rf@opensource.wolfsonmicro.com> |
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 1/2] of: Make of_find_property_value_of_size take a length range |
| Date | Mon, 12 Sep 2016 15:10:02 +0200 |
| Message-ID | <sgz9M-3JB-55@gated-at.bofh.it> (permalink) |
| X-Original-To | <robh+dt@kernel.org> |
| Authentication-Results | ppops.net; spf=none smtp.mailfrom=rf@opensource.wolfsonmicro.com |
| X-Mailer | git-send-email 1.9.1 |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| X-Proofpoint-Spam-Details | rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609020000 definitions=main-1609120201 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 122 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | <frowand.list@gmail.com>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <patches@opensource.wolfsonmicro.com> |
| X-Original-Date | Mon, 12 Sep 2016 14:01:28 +0100 |
| X-Original-Message-ID | <1473685289-21830-1-git-send-email-rf@opensource.wolfsonmicro.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1481261 |
Show key headers only | View raw
In preparation for adding variable-length array reads, change
of_find_property_value_of_size so that it takes an optional
maximum length. If the maximum is passed as 0, the behaviour is
unchanged and it will return a property if it's >= the requested
minimum length. If maximum is non-zero it will only return a
property whose length is min <= l <= max.
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
---
drivers/of/base.c | 39 +++++++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3ce6953..b853737 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1146,16 +1146,18 @@ EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);
*
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
- * @len: requested length of property value
+ * @min: minimum allowed length of property value
+ * @max: maximum allowed length of property value (0 means unlimited)
+ * @len: if !=NULL, actual length is written to here
*
* Search for a property in a device node and valid the requested size.
* Returns the property value on success, -EINVAL if the property does not
* exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
- * property data isn't large enough.
+ * property data is too small or too large.
*
*/
static void *of_find_property_value_of_size(const struct device_node *np,
- const char *propname, u32 len)
+ const char *propname, u32 min, u32 max, size_t *len)
{
struct property *prop = of_find_property(np, propname, NULL);
@@ -1163,9 +1165,14 @@ static void *of_find_property_value_of_size(const struct device_node *np,
return ERR_PTR(-EINVAL);
if (!prop->value)
return ERR_PTR(-ENODATA);
- if (len > prop->length)
+ if (prop->length < min)
+ return ERR_PTR(-EOVERFLOW);
+ if (max && prop->length > max)
return ERR_PTR(-EOVERFLOW);
+ if (len)
+ *len = prop->length;
+
return prop->value;
}
@@ -1189,7 +1196,9 @@ int of_property_read_u32_index(const struct device_node *np,
u32 index, u32 *out_value)
{
const u32 *val = of_find_property_value_of_size(np, propname,
- ((index + 1) * sizeof(*out_value)));
+ ((index + 1) * sizeof(*out_value)),
+ 0,
+ NULL);
if (IS_ERR(val))
return PTR_ERR(val);
@@ -1221,7 +1230,9 @@ int of_property_read_u8_array(const struct device_node *np,
const char *propname, u8 *out_values, size_t sz)
{
const u8 *val = of_find_property_value_of_size(np, propname,
- (sz * sizeof(*out_values)));
+ (sz * sizeof(*out_values)),
+ 0,
+ NULL);
if (IS_ERR(val))
return PTR_ERR(val);
@@ -1254,7 +1265,9 @@ int of_property_read_u16_array(const struct device_node *np,
const char *propname, u16 *out_values, size_t sz)
{
const __be16 *val = of_find_property_value_of_size(np, propname,
- (sz * sizeof(*out_values)));
+ (sz * sizeof(*out_values)),
+ 0,
+ NULL);
if (IS_ERR(val))
return PTR_ERR(val);
@@ -1286,7 +1299,9 @@ int of_property_read_u32_array(const struct device_node *np,
size_t sz)
{
const __be32 *val = of_find_property_value_of_size(np, propname,
- (sz * sizeof(*out_values)));
+ (sz * sizeof(*out_values)),
+ 0,
+ NULL);
if (IS_ERR(val))
return PTR_ERR(val);
@@ -1314,7 +1329,9 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
u64 *out_value)
{
const __be32 *val = of_find_property_value_of_size(np, propname,
- sizeof(*out_value));
+ sizeof(*out_value),
+ 0,
+ NULL);
if (IS_ERR(val))
return PTR_ERR(val);
@@ -1345,7 +1362,9 @@ int of_property_read_u64_array(const struct device_node *np,
size_t sz)
{
const __be32 *val = of_find_property_value_of_size(np, propname,
- (sz * sizeof(*out_values)));
+ (sz * sizeof(*out_values)),
+ 0,
+ NULL);
if (IS_ERR(val))
return PTR_ERR(val);
--
1.9.1
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH v2 1/2] of: Make of_find_property_value_of_size take a length range Richard Fitzgerald <rf@opensource.wolfsonmicro.com> - 2016-09-12 15:10 +0200 [PATCH v2 2/2] of: Add array read functions with min/max size limits Richard Fitzgerald <rf@opensource.wolfsonmicro.com> - 2016-09-12 15:10 +0200 Re: [PATCH v2 1/2] of: Make of_find_property_value_of_size take a length range Rob Herring <robh@kernel.org> - 2016-09-15 15:40 +0200
csiph-web