Skip to content

Commit 263dbd3

Browse files
robherringJassi Brar
authored andcommitted
mailbox: Use of_property_match_string() instead of open-coding
Use of_property_match_string() instead of open-coding the search. With this, of_get_property() can be removed as there is no need to check for "mbox-names" presence first. This is part of a larger effort to remove callers of of_get_property() and similar functions. of_get_property() leaks the DT property data pointer which is a problem for dynamically allocated nodes which may be freed. Signed-off-by: Rob Herring (Arm) <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent dc09f00 commit 263dbd3

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

drivers/mailbox/mailbox.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -450,30 +450,20 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
450450
const char *name)
451451
{
452452
struct device_node *np = cl->dev->of_node;
453-
struct property *prop;
454-
const char *mbox_name;
455-
int index = 0;
453+
int index;
456454

457455
if (!np) {
458456
dev_err(cl->dev, "%s() currently only supports DT\n", __func__);
459457
return ERR_PTR(-EINVAL);
460458
}
461459

462-
if (!of_get_property(np, "mbox-names", NULL)) {
463-
dev_err(cl->dev,
464-
"%s() requires an \"mbox-names\" property\n", __func__);
460+
index = of_property_match_string(np, "mbox-names", name);
461+
if (index < 0) {
462+
dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n",
463+
__func__, name);
465464
return ERR_PTR(-EINVAL);
466465
}
467-
468-
of_property_for_each_string(np, "mbox-names", prop, mbox_name) {
469-
if (!strncmp(name, mbox_name, strlen(name)))
470-
return mbox_request_channel(cl, index);
471-
index++;
472-
}
473-
474-
dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n",
475-
__func__, name);
476-
return ERR_PTR(-EINVAL);
466+
return mbox_request_channel(cl, index);
477467
}
478468
EXPORT_SYMBOL_GPL(mbox_request_channel_byname);
479469

0 commit comments

Comments
 (0)