[PATCH] component: fix loop condition to call unbind() if bind() fails
From: Banajit Goswami During component_bind_all(), if bind() fails for any particular component associated with a master, unbind() should be called for all previous components in that master's match array, whose bind() might have completed successfully. As per the current logic, if bind() fails for the component at position 'n' in the master's match array, it would start calling unbind() from component in 'n'th position itself and work backwards, and will always skip calling unbind() for component in 0th position in the master's match array. Fix this by updating the loop condition, and the logic to refer to the components in master's match array, so that unbind() is called for all components starting from 'n-1'st position in the array, until (and including) component in 0th position. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 8946dfe..e8d676f 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -536,9 +536,9 @@ int component_bind_all(struct device *master_dev, void *data) } if (ret != 0) { - for (; i--; ) - if (!master->match->compare[i].duplicate) { - c = master->match->compare[i].component; + for (; i > 0; i--) + if (!master->match->compare[i - 1].duplicate) { + c = master->match->compare[i - 1].component; component_unbind(c, master, data); } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH] component: fix loop condition to call unbind() if bind() fails
From: Banajit Goswami During component_bind_all(), if bind() fails for any particular component associated with a master, unbind() should be called for all previous components in that master's match array, whose bind() might have completed successfully. As per the current logic, if bind() fails for the component at position 'n' in the master's match array, it would start calling unbind() from component in 'n'th position itself and work backwards, and will always skip calling unbind() for component in 0th position in the master's match array. Fix this by updating the loop condition, and the logic to refer to the components in master's match array, so that unbind() is called for all components starting from 'n-1'st position in the array, until (and including) component in 0th position. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 8946dfe..e8d676f 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -536,9 +536,9 @@ int component_bind_all(struct device *master_dev, void *data) } if (ret != 0) { - for (; i--; ) - if (!master->match->compare[i].duplicate) { - c = master->match->compare[i].component; + for (; i > 0; i--) + if (!master->match->compare[i - 1].duplicate) { + c = master->match->compare[i - 1].component; component_unbind(c, master, data); } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH][RESEND 2] component: enhance handling of devres group for master
From: Banajit Goswami The devres group opened for a master is left open-ended (without devres_group_close) even after bind() is complete. Similarly, while releasing the devres resources for master, the most recently opened devres group is selected, and released without identifying the targeted group. As the devres group opened before master bind was never closed, there may have unintended consequences of releasing devres resources that were allocated after master bind() function was complete. Change adds a devres_group_close() after bind() call to master, to encapsulate the resources allocated during bind, and then use a group ID to specifically identify the group in release, so that during master unbind, only the resources that are part of that specific devres group, are released. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f..f9ce937 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -155,17 +155,19 @@ static int try_to_bring_up_master(struct master *master, return 0; } - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->dev, master, GFP_KERNEL)) return -ENOMEM; /* Found all components */ ret = master->ops->bind(master->dev); if (ret < 0) { - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); dev_info(master->dev, "master bind failed: %d\n", ret); return ret; } + devres_close_group(master->dev, master); + master->bound = true; return 1; } @@ -190,7 +192,7 @@ static void take_down_master(struct master *master) { if (master->bound) { master->ops->unbind(master->dev); - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); master->bound = false; } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH][RESEND 2] component: enhance handling of devres group for master
From: Banajit Goswami The devres group opened for a master is left open-ended (without devres_group_close) even after bind() is complete. Similarly, while releasing the devres resources for master, the most recently opened devres group is selected, and released without identifying the targeted group. As the devres group opened before master bind was never closed, there may have unintended consequences of releasing devres resources that were allocated after master bind() function was complete. Change adds a devres_group_close() after bind() call to master, to encapsulate the resources allocated during bind, and then use a group ID to specifically identify the group in release, so that during master unbind, only the resources that are part of that specific devres group, are released. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f..f9ce937 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -155,17 +155,19 @@ static int try_to_bring_up_master(struct master *master, return 0; } - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->dev, master, GFP_KERNEL)) return -ENOMEM; /* Found all components */ ret = master->ops->bind(master->dev); if (ret < 0) { - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); dev_info(master->dev, "master bind failed: %d\n", ret); return ret; } + devres_close_group(master->dev, master); + master->bound = true; return 1; } @@ -190,7 +192,7 @@ static void take_down_master(struct master *master) { if (master->bound) { master->ops->unbind(master->dev); - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); master->bound = false; } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH][RESEND] component: enhance handling of devres group for master
From: Banajit Goswami The devres group opened for a master is left open-ended (without devres_group_close) even after bind() is complete. Similarly, while releasing the devres resources for master, the most recently opened devres group is selected, and released without identifying the targeted group. As the devres group opened before master bind was never closed, there may have unintended consequences of releasing devres resources that were allocated after master bind() function was complete. Change adds a devres_group_close() after bind() call to master, to encapsulate the resources allocated during bind, and then use a group ID to specifically identify the group in release, so that during master unbind, only the resources that are part of that specific devres group, are released. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f..f9ce937 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -155,17 +155,19 @@ static int try_to_bring_up_master(struct master *master, return 0; } - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->dev, master, GFP_KERNEL)) return -ENOMEM; /* Found all components */ ret = master->ops->bind(master->dev); if (ret < 0) { - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); dev_info(master->dev, "master bind failed: %d\n", ret); return ret; } + devres_close_group(master->dev, master); + master->bound = true; return 1; } @@ -190,7 +192,7 @@ static void take_down_master(struct master *master) { if (master->bound) { master->ops->unbind(master->dev); - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); master->bound = false; } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH][RESEND] component: enhance handling of devres group for master
From: Banajit Goswami The devres group opened for a master is left open-ended (without devres_group_close) even after bind() is complete. Similarly, while releasing the devres resources for master, the most recently opened devres group is selected, and released without identifying the targeted group. As the devres group opened before master bind was never closed, there may have unintended consequences of releasing devres resources that were allocated after master bind() function was complete. Change adds a devres_group_close() after bind() call to master, to encapsulate the resources allocated during bind, and then use a group ID to specifically identify the group in release, so that during master unbind, only the resources that are part of that specific devres group, are released. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f..f9ce937 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -155,17 +155,19 @@ static int try_to_bring_up_master(struct master *master, return 0; } - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->dev, master, GFP_KERNEL)) return -ENOMEM; /* Found all components */ ret = master->ops->bind(master->dev); if (ret < 0) { - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); dev_info(master->dev, "master bind failed: %d\n", ret); return ret; } + devres_close_group(master->dev, master); + master->bound = true; return 1; } @@ -190,7 +192,7 @@ static void take_down_master(struct master *master) { if (master->bound) { master->ops->unbind(master->dev); - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); master->bound = false; } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH] component: enhance handling of devres group for master
From: Banajit Goswami The devres group opened for a master is left open-ended (without devres_group_close) even after bind() is complete. Similarly, while releasing the devres resources for master, the most recently opened devres group is selected, and released without identifying the targeted group. As the devres group opened before master bind was never closed, there may have unintended consequences of releasing devres resources that were allocated after master bind() function was complete. Change adds a devres_group_close() after bind() call to master, to encapsulate the resources allocated during bind, and then use a group ID to specifically identify the group in release, so that during master unbind, only the resources that are part of that specific devres group, are released. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f..f9ce937 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -155,17 +155,19 @@ static int try_to_bring_up_master(struct master *master, return 0; } - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->dev, master, GFP_KERNEL)) return -ENOMEM; /* Found all components */ ret = master->ops->bind(master->dev); if (ret < 0) { - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); dev_info(master->dev, "master bind failed: %d\n", ret); return ret; } + devres_close_group(master->dev, master); + master->bound = true; return 1; } @@ -190,7 +192,7 @@ static void take_down_master(struct master *master) { if (master->bound) { master->ops->unbind(master->dev); - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); master->bound = false; } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH] component: enhance handling of devres group for master
From: Banajit Goswami The devres group opened for a master is left open-ended (without devres_group_close) even after bind() is complete. Similarly, while releasing the devres resources for master, the most recently opened devres group is selected, and released without identifying the targeted group. As the devres group opened before master bind was never closed, there may have unintended consequences of releasing devres resources that were allocated after master bind() function was complete. Change adds a devres_group_close() after bind() call to master, to encapsulate the resources allocated during bind, and then use a group ID to specifically identify the group in release, so that during master unbind, only the resources that are part of that specific devres group, are released. Signed-off-by: Banajit Goswami --- drivers/base/component.c | 8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/base/component.c b/drivers/base/component.c index 89b032f..f9ce937 100644 --- a/drivers/base/component.c +++ b/drivers/base/component.c @@ -155,17 +155,19 @@ static int try_to_bring_up_master(struct master *master, return 0; } - if (!devres_open_group(master->dev, NULL, GFP_KERNEL)) + if (!devres_open_group(master->dev, master, GFP_KERNEL)) return -ENOMEM; /* Found all components */ ret = master->ops->bind(master->dev); if (ret < 0) { - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); dev_info(master->dev, "master bind failed: %d\n", ret); return ret; } + devres_close_group(master->dev, master); + master->bound = true; return 1; } @@ -190,7 +192,7 @@ static void take_down_master(struct master *master) { if (master->bound) { master->ops->unbind(master->dev); - devres_release_group(master->dev, NULL); + devres_release_group(master->dev, master); master->bound = false; } } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project