media: dvb-core: remove redundant new_node cleanup in dvb_register_device
PATCH v2 1/1 media: dvb-core: remove redundant new_node cleanup in dvb_register_device
The error handling paths in dvb_register_device repeatedly check if (new_node) before cleanup. However, if new_node allocation fails, the function returns immediately and does not reach these branches. Thus, these conditionals are redundant and can be removed for code clarity and maintainability.
--- drivers/media/dvb-core/dvbdev.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/media/dvb-core/dvbdev.c +0 -15
@@ -534,11 +534,6 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, minor =nums2minor (adap->num, type, id);#endif if (minor >=MAX_DVB_MINORS ) { -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - }list_del (&dvbdev->list_head);kfree (dvbdev); *pdvbdev =NULL ;
@@ -554,11 +549,6 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,if (ret) {pr_err ("%s: dvb_register_media_device failed to create the mediagraph\n" , __func__); -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - }dvb_media_device_free (dvbdev);list_del (&dvbdev->list_head);kfree (dvbdev);
@@ -573,11 +563,6 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,if (IS_ERR (clsdev)) {pr_err ("%s: failed to create device dvb%d.%s%d (%ld)\n" , __func__, adap->num, dnames[type], id,PTR_ERR (clsdev)); -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - }dvb_media_device_free (dvbdev);list_del (&dvbdev->list_head);kfree (dvbdev);
Signature · 1 line
2.20.1
PATCH v3 1/1 media: dvb-core: remove redundant new_node cleanup in dvb_register_device
The error handling paths in dvb_register_device repeatedly check if (new_node) before cleanup. However, if new_node allocation fails, the function returns immediately and does not reach these branches. Thus, these conditionals are redundant and can be removed for code clarity and maintainability.
---
Changes in v3:
- Modify the redundant logic
- Link to v2: https://lore.kernel.org/all/[email protected]/
--- drivers/media/dvb-core/dvbdev.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/media/dvb-core/dvbdev.c +9 -15
@@ -534,11 +534,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, minor =nums2minor (adap->num, type, id);#endif if (minor >=MAX_DVB_MINORS ) { -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - } +list_del (&new_node->list_head); +kfree (dvbdevfops); +kfree (new_node);list_del (&dvbdev->list_head);kfree (dvbdev); *pdvbdev =NULL ;
@@ -554,11 +552,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,if (ret) {pr_err ("%s: dvb_register_media_device failed to create the mediagraph\n" , __func__); -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - } +list_del (&new_node->list_head); +kfree (dvbdevfops); +kfree (new_node);dvb_media_device_free (dvbdev);list_del (&dvbdev->list_head);kfree (dvbdev);
@@ -573,11 +569,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,if (IS_ERR (clsdev)) {pr_err ("%s: failed to create device dvb%d.%s%d (%ld)\n" , __func__, adap->num, dnames[type], id,PTR_ERR (clsdev)); -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - } +list_del (&new_node->list_head); +kfree (dvbdevfops); +kfree (new_node);dvb_media_device_free (dvbdev);list_del (&dvbdev->list_head);kfree (dvbdev);
Signature · 1 line
2.20.1
PATCH RESEND v3 1/1 media: dvb-core: remove redundant new_node cleanup in dvb_register_device
The error handling paths in dvb_register_device repeatedly check if (new_node) before cleanup. However, if new_node allocation fails, the function returns immediately and does not reach these branches. Thus, these conditionals are redundant and can be removed for code clarity and maintainability.
---
Changes in v3:
- Modify the redundant logic
- Link to v2: https://lore.kernel.org/all/[email protected]/
--- drivers/media/dvb-core/dvbdev.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/media/dvb-core/dvbdev.c +9 -15
@@ -534,11 +534,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, minor =nums2minor (adap->num, type, id);#endif if (minor >=MAX_DVB_MINORS ) { -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - } +list_del (&new_node->list_head); +kfree (dvbdevfops); +kfree (new_node);list_del (&dvbdev->list_head);kfree (dvbdev); *pdvbdev =NULL ;
@@ -554,11 +552,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,if (ret) {pr_err ("%s: dvb_register_media_device failed to create the mediagraph\n" , __func__); -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - } +list_del (&new_node->list_head); +kfree (dvbdevfops); +kfree (new_node);dvb_media_device_free (dvbdev);list_del (&dvbdev->list_head);kfree (dvbdev);
@@ -573,11 +569,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,if (IS_ERR (clsdev)) {pr_err ("%s: failed to create device dvb%d.%s%d (%ld)\n" , __func__, adap->num, dnames[type], id,PTR_ERR (clsdev)); -if (new_node) { -list_del (&new_node->list_head); -kfree (dvbdevfops); -kfree (new_node); - } +list_del (&new_node->list_head); +kfree (dvbdevfops); +kfree (new_node);dvb_media_device_free (dvbdev);list_del (&dvbdev->list_head);kfree (dvbdev);
Signature · 1 line
2.20.1