public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pps: add an error check in parport_attach
@ 2024-08-13  3:08 Ma Ke
  2024-08-13  9:11 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Ma Ke @ 2024-08-13  3:08 UTC (permalink / raw)
  To: giometti, christophe.jaillet, linux, gregkh, sudipm.mukherjee,
	make24, akpm
  Cc: linux-kernel, stable

In parport_attach, the return value of ida_alloc is unchecked, witch leads
to the use of an invalid index value.

To address this issue, index should be checked. When the index value is
abnormal, the device should be freed.

Found by code review, compile tested only.

Cc: stable@vger.kernel.org
Fixes: 55dbc5b5174d ("pps: remove usage of the deprecated ida_simple_xx() API")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
 drivers/pps/clients/pps_parport.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/pps/clients/pps_parport.c b/drivers/pps/clients/pps_parport.c
index 63d03a0df5cc..9ab7f6961e42 100644
--- a/drivers/pps/clients/pps_parport.c
+++ b/drivers/pps/clients/pps_parport.c
@@ -149,6 +149,11 @@ static void parport_attach(struct parport *port)
 	}
 
 	index = ida_alloc(&pps_client_index, GFP_KERNEL);
+	if (index < 0) {
+		pr_err("failed to get index\n");
+		goto err_free_device;
+	}
+
 	memset(&pps_client_cb, 0, sizeof(pps_client_cb));
 	pps_client_cb.private = device;
 	pps_client_cb.irq_func = parport_irq;
@@ -159,7 +164,7 @@ static void parport_attach(struct parport *port)
 						    index);
 	if (!device->pardev) {
 		pr_err("couldn't register with %s\n", port->name);
-		goto err_free;
+		goto err_free_ida;
 	}
 
 	if (parport_claim_or_block(device->pardev) < 0) {
@@ -187,8 +192,9 @@ static void parport_attach(struct parport *port)
 	parport_release(device->pardev);
 err_unregister_dev:
 	parport_unregister_device(device->pardev);
-err_free:
+err_free_ida:
 	ida_free(&pps_client_index, index);
+err_free_device:
 	kfree(device);
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-13  9:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13  3:08 [PATCH] pps: add an error check in parport_attach Ma Ke
2024-08-13  9:11 ` Greg KH
2024-08-13  9:51   ` Ma Ke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox