[PATCH v2 07/21] bus: fsl-mc: use match_string() helper
match_string() returns the index of an array for a matching string, which can be used instead of open coded variant. Reviewed-by: Andy Shevchenko Cc: Stuart Yoder Cc: Laurentiu Tudor Signed-off-by: Yisheng Xie --- v2: - add Reviewed-by tag. drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +--- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c index fb1442b..63c4735 100644 --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c @@ -156,22 +156,6 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device [FSL_MC_POOL_IRQ] = "irq", }; -static int __must_check object_type_to_pool_type(const char *object_type, -enum fsl_mc_pool_type - *pool_type) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) { - if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) { - *pool_type = i; - return 0; - } - } - - return -EINVAL; -} - int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, enum fsl_mc_pool_type pool_type, struct fsl_mc_resource **new_resource) @@ -581,9 +565,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev) return -EINVAL; mc_bus = to_fsl_mc_bus(mc_bus_dev); - error = object_type_to_pool_type(mc_dev->obj_desc.type, _type); - if (error < 0) - return error; + pool_type = match_string(fsl_mc_pool_type_strings, +ARRAY_SIZE(fsl_mc_pool_type_strings), +mc_dev->obj_desc.type); + if (pool_type < 0) + return pool_type; error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev); if (error < 0) -- 1.7.12.4
[PATCH v2 07/21] bus: fsl-mc: use match_string() helper
match_string() returns the index of an array for a matching string, which can be used instead of open coded variant. Reviewed-by: Andy Shevchenko Cc: Stuart Yoder Cc: Laurentiu Tudor Signed-off-by: Yisheng Xie --- v2: - add Reviewed-by tag. drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +--- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c index fb1442b..63c4735 100644 --- a/drivers/bus/fsl-mc/fsl-mc-allocator.c +++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c @@ -156,22 +156,6 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device [FSL_MC_POOL_IRQ] = "irq", }; -static int __must_check object_type_to_pool_type(const char *object_type, -enum fsl_mc_pool_type - *pool_type) -{ - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) { - if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) { - *pool_type = i; - return 0; - } - } - - return -EINVAL; -} - int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, enum fsl_mc_pool_type pool_type, struct fsl_mc_resource **new_resource) @@ -581,9 +565,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev) return -EINVAL; mc_bus = to_fsl_mc_bus(mc_bus_dev); - error = object_type_to_pool_type(mc_dev->obj_desc.type, _type); - if (error < 0) - return error; + pool_type = match_string(fsl_mc_pool_type_strings, +ARRAY_SIZE(fsl_mc_pool_type_strings), +mc_dev->obj_desc.type); + if (pool_type < 0) + return pool_type; error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev); if (error < 0) -- 1.7.12.4