Re: [PATCH 2/5] um: port: Delete three error messages for a failed memory allocation
>> +++ b/arch/um/drivers/port_kern.c >> @@ -87,11 +87,8 @@ static int port_accept(struct port_list *port) >> } >> >> conn = kmalloc(sizeof(*conn), GFP_ATOMIC); >> -if (conn == NULL) { >> -printk(KERN_ERR "port_accept : failed to allocate " >> - "connection\n"); >> +if (!conn) >> goto out_close; >> -} >> *conn = ((struct connection) >> { .list = LIST_HEAD_INIT(conn->list), >>.fd = fd, > > I don't see how this eliminates a possible error. The suggested change affects three coding style issues at this place. * Repetition of an out-of-memory message See also: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf * Unwanted splitting of a message string * Usage of a specific preprocessor symbol > !x is something you use with something that is conceptually a Boolean. Pointers can be also treated in this way, can't they? Regards, Markus
Re: [PATCH 2/5] um: port: Delete three error messages for a failed memory allocation
>> +++ b/arch/um/drivers/port_kern.c >> @@ -87,11 +87,8 @@ static int port_accept(struct port_list *port) >> } >> >> conn = kmalloc(sizeof(*conn), GFP_ATOMIC); >> -if (conn == NULL) { >> -printk(KERN_ERR "port_accept : failed to allocate " >> - "connection\n"); >> +if (!conn) >> goto out_close; >> -} >> *conn = ((struct connection) >> { .list = LIST_HEAD_INIT(conn->list), >>.fd = fd, > > I don't see how this eliminates a possible error. The suggested change affects three coding style issues at this place. * Repetition of an out-of-memory message See also: http://events.linuxfoundation.org/sites/events/files/slides/LCJ16-Refactor_Strings-WSang_0.pdf * Unwanted splitting of a message string * Usage of a specific preprocessor symbol > !x is something you use with something that is conceptually a Boolean. Pointers can be also treated in this way, can't they? Regards, Markus
Re: [PATCH 2/5] um: port: Delete three error messages for a failed memory allocation
> --- a/arch/um/drivers/port_kern.c > +++ b/arch/um/drivers/port_kern.c > @@ -87,11 +87,8 @@ static int port_accept(struct port_list *port) > } > > conn = kmalloc(sizeof(*conn), GFP_ATOMIC); > - if (conn == NULL) { > - printk(KERN_ERR "port_accept : failed to allocate " > -"connection\n"); > + if (!conn) > goto out_close; > - } > *conn = ((struct connection) > { .list = LIST_HEAD_INIT(conn->list), > .fd = fd, I don't see how this eliminates a possible error. It should behave exactly the same. To me, this is an expressiveness issue. !x is something you use with something that is conceptually a Boolean. x == NULL is a question about a pointer, which is the case here. Jeff -- Jeff Dike AddToIt 978-254-0789 (o) 978-394-8986 (c)
Re: [PATCH 2/5] um: port: Delete three error messages for a failed memory allocation
> --- a/arch/um/drivers/port_kern.c > +++ b/arch/um/drivers/port_kern.c > @@ -87,11 +87,8 @@ static int port_accept(struct port_list *port) > } > > conn = kmalloc(sizeof(*conn), GFP_ATOMIC); > - if (conn == NULL) { > - printk(KERN_ERR "port_accept : failed to allocate " > -"connection\n"); > + if (!conn) > goto out_close; > - } > *conn = ((struct connection) > { .list = LIST_HEAD_INIT(conn->list), > .fd = fd, I don't see how this eliminates a possible error. It should behave exactly the same. To me, this is an expressiveness issue. !x is something you use with something that is conceptually a Boolean. x == NULL is a question about a pointer, which is the case here. Jeff -- Jeff Dike AddToIt 978-254-0789 (o) 978-394-8986 (c)
[PATCH 2/5] um: port: Delete three error messages for a failed memory allocation
From: Markus ElfringDate: Wed, 18 Jan 2017 22:00:14 +0100 The script "checkpatch.pl" pointed information out like the following. WARNING: Possible unnecessary 'out of memory' message Thus fix the affected source code places. Signed-off-by: Markus Elfring --- arch/um/drivers/port_kern.c | 13 +++-- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/arch/um/drivers/port_kern.c b/arch/um/drivers/port_kern.c index b2bbda21c5f3..c96741e920f5 100644 --- a/arch/um/drivers/port_kern.c +++ b/arch/um/drivers/port_kern.c @@ -87,11 +87,8 @@ static int port_accept(struct port_list *port) } conn = kmalloc(sizeof(*conn), GFP_ATOMIC); - if (conn == NULL) { - printk(KERN_ERR "port_accept : failed to allocate " - "connection\n"); + if (!conn) goto out_close; - } *conn = ((struct connection) { .list = LIST_HEAD_INIT(conn->list), .fd = fd, @@ -170,10 +167,8 @@ void *port_data(int port_num) goto found; } port = kmalloc(sizeof(struct port_list), GFP_KERNEL); - if (port == NULL) { - printk(KERN_ERR "Allocation of port list failed\n"); + if (!port) goto out; - } fd = port_listen_fd(port_num); if (fd < 0) { @@ -202,10 +197,8 @@ void *port_data(int port_num) found: dev = kmalloc(sizeof(struct port_dev), GFP_KERNEL); - if (dev == NULL) { - printk(KERN_ERR "Allocation of port device entry failed\n"); + if (!dev) goto out; - } *dev = ((struct port_dev) { .port = port, .helper_pid = -1, -- 2.11.0
[PATCH 2/5] um: port: Delete three error messages for a failed memory allocation
From: Markus Elfring Date: Wed, 18 Jan 2017 22:00:14 +0100 The script "checkpatch.pl" pointed information out like the following. WARNING: Possible unnecessary 'out of memory' message Thus fix the affected source code places. Signed-off-by: Markus Elfring --- arch/um/drivers/port_kern.c | 13 +++-- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/arch/um/drivers/port_kern.c b/arch/um/drivers/port_kern.c index b2bbda21c5f3..c96741e920f5 100644 --- a/arch/um/drivers/port_kern.c +++ b/arch/um/drivers/port_kern.c @@ -87,11 +87,8 @@ static int port_accept(struct port_list *port) } conn = kmalloc(sizeof(*conn), GFP_ATOMIC); - if (conn == NULL) { - printk(KERN_ERR "port_accept : failed to allocate " - "connection\n"); + if (!conn) goto out_close; - } *conn = ((struct connection) { .list = LIST_HEAD_INIT(conn->list), .fd = fd, @@ -170,10 +167,8 @@ void *port_data(int port_num) goto found; } port = kmalloc(sizeof(struct port_list), GFP_KERNEL); - if (port == NULL) { - printk(KERN_ERR "Allocation of port list failed\n"); + if (!port) goto out; - } fd = port_listen_fd(port_num); if (fd < 0) { @@ -202,10 +197,8 @@ void *port_data(int port_num) found: dev = kmalloc(sizeof(struct port_dev), GFP_KERNEL); - if (dev == NULL) { - printk(KERN_ERR "Allocation of port device entry failed\n"); + if (!dev) goto out; - } *dev = ((struct port_dev) { .port = port, .helper_pid = -1, -- 2.11.0