[Top] [All Lists]

Re: [PATCH 5/5] drivers/serial: Return -ENOMEM on memory allocation fail

To: Julia Lawall <>
Subject: Re: [PATCH 5/5] drivers/serial: Return -ENOMEM on memory allocation failure
From: Patrick Gefre <>
Date: Wed, 11 Aug 2010 10:59:47 -0500
In-reply-to: <>
Original-recipient: rfc822;
References: <>
User-agent: Thunderbird (X11/20090105)
Julia Lawall wrote:
From: Julia Lawall <>

In this code, 0 is returned on memory allocation failure, even though other
failures return -ENOMEM or other similar values.

A simplified version of the semantic match that finds this problem is as
follows: (

// <smpl>
expression ret;
expression x,e1,e2,e3;

ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
  return ret;
// </smpl>

Signed-off-by: Julia Lawall <>

Signed-off-by: Pat Gefre <>

I believe this code also leaks earlier instances of port, which are only
referenced by card_ptr, which is freed in the error handling code at the
end of the function.  A lot of operations are done on port on each
iteration, however, so I'm not sure whether it is good enough to just free
them.  Perhaps there is some way to call ioc3uart_remove?

Yes you are right, there should be something like this for out4:

        for (phys_port = 0; phys_port < PORTS_PER_CARD; phys_port++) {
                port = card_ptr->ic_port[phys_port].icp_port;
                if (port) {
                                       (void *)port->ip_cpu_ringbuf,
        return ret;

 drivers/serial/ioc3_serial.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/serial/ioc3_serial.c b/drivers/serial/ioc3_serial.c
index 93de907..800c546 100644
--- a/drivers/serial/ioc3_serial.c
+++ b/drivers/serial/ioc3_serial.c
@@ -2044,6 +2044,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct 
ioc3_driver_data *idd)
                if (!port) {
                               "IOC3 serial memory not available for port\n");
+                       ret = -ENOMEM;
                        goto out4;

<Prev in Thread] Current Thread [Next in Thread>