Skip to content

Commit 62c5a01

Browse files
Ma Kegregkh
authored andcommitted
pps: add an error check in parport_attach
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: [email protected] Fixes: fb56d97 ("pps: client: use new parport device model") Signed-off-by: Ma Ke <[email protected]> Acked-by: Rodolfo Giometti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4302795 commit 62c5a01

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/pps/clients/pps_parport.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ static void parport_attach(struct parport *port)
149149
}
150150

151151
index = ida_alloc(&pps_client_index, GFP_KERNEL);
152+
if (index < 0)
153+
goto err_free_device;
154+
152155
memset(&pps_client_cb, 0, sizeof(pps_client_cb));
153156
pps_client_cb.private = device;
154157
pps_client_cb.irq_func = parport_irq;
@@ -159,7 +162,7 @@ static void parport_attach(struct parport *port)
159162
index);
160163
if (!device->pardev) {
161164
pr_err("couldn't register with %s\n", port->name);
162-
goto err_free;
165+
goto err_free_ida;
163166
}
164167

165168
if (parport_claim_or_block(device->pardev) < 0) {
@@ -187,8 +190,9 @@ static void parport_attach(struct parport *port)
187190
parport_release(device->pardev);
188191
err_unregister_dev:
189192
parport_unregister_device(device->pardev);
190-
err_free:
193+
err_free_ida:
191194
ida_free(&pps_client_index, index);
195+
err_free_device:
192196
kfree(device);
193197
}
194198

0 commit comments

Comments
 (0)