[PATCH] USB: usbserial.c fixup
create_serial, get_free_serial and usb_serial_probe all do pretty much the same thing. I'd like to reorg this into create_serial does all the alloc and most of the setup, and get_free_serial just fills in the MAGIC. There's currently a memory leak: if create_serial is called at probe time or calc_ports time, and then get_free_serial returns NULL because the table has no entries left, that usb_serial struct is leaked. get_free_serial doesn't check properly for free slots. The middle loop doesn't terminate when the end of the table is reached, although the assignment loop later does. The effect is that stuff past the end of the table is allowed to decide if there's free space or not, and occasionally it'll say "yes" and then the assignment loop will only allocate slots up to the end of the table, preventing memory scribbling. I haven't fixed any of this just yet because I'm not sure what the intended behaviour is. Should get_free_serial allocate as many slots as possible, or just be all or nothing? Similarly, I don't see a problem with calling create_serial early in usb_serial_probe, and removing the alloc code from get_free_serial; this would fix the leak. Ah heck, here's a patch. This is what I think things should look like. get_free_serial is all or none, the leak is fixed and create_serial does all the allocation.
Showing
Please register or sign in to comment