Message ID | 20200814101000.2463612-1-fazilyildiran@gmail.com |
---|---|
State | Changes Requested |
Delegated to: | David Miller |
Headers | show |
Series | net: qrtr: fix usage of idr in port assignment to socket | expand |
From: Necip Fazil Yildiran <fazilyildiran@gmail.com> Date: Fri, 14 Aug 2020 10:10:00 +0000 > diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c > index b4c0db0b7d31..52d0707df776 100644 > --- a/net/qrtr/qrtr.c > +++ b/net/qrtr/qrtr.c > @@ -693,22 +693,24 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) > static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) > { > int rc; > + u32 min_port; Please use reverse christmas tree ordering for local variables.
On Fri, Aug 14, 2020 at 10:55 PM David Miller <davem@davemloft.net> wrote: > > From: Necip Fazil Yildiran <fazilyildiran@gmail.com> > Date: Fri, 14 Aug 2020 10:10:00 +0000 > > > diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c > > index b4c0db0b7d31..52d0707df776 100644 > > --- a/net/qrtr/qrtr.c > > +++ b/net/qrtr/qrtr.c > > @@ -693,22 +693,24 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) > > static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) > > { > > int rc; > > + u32 min_port; > > Please use reverse christmas tree ordering for local variables. If Dave's comment is fixed: Reviewed-by: Dmitry Vyukov <dvyukov@google.com> (add this tag to the v2 of this patch). Just in case: "reverse christmas tree" is when variable declarations are sorted by line length (longest first).
diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index b4c0db0b7d31..52d0707df776 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -693,22 +693,24 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) static int qrtr_port_assign(struct qrtr_sock *ipc, int *port) { int rc; + u32 min_port; mutex_lock(&qrtr_port_lock); if (!*port) { - rc = idr_alloc(&qrtr_ports, ipc, - QRTR_MIN_EPH_SOCKET, QRTR_MAX_EPH_SOCKET + 1, - GFP_ATOMIC); - if (rc >= 0) - *port = rc; + min_port = QRTR_MIN_EPH_SOCKET; + rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, QRTR_MAX_EPH_SOCKET, GFP_ATOMIC); + if (!rc) + *port = min_port; } else if (*port < QRTR_MIN_EPH_SOCKET && !capable(CAP_NET_ADMIN)) { rc = -EACCES; } else if (*port == QRTR_PORT_CTRL) { - rc = idr_alloc(&qrtr_ports, ipc, 0, 1, GFP_ATOMIC); + min_port = 0; + rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, 0, GFP_ATOMIC); } else { - rc = idr_alloc(&qrtr_ports, ipc, *port, *port + 1, GFP_ATOMIC); - if (rc >= 0) - *port = rc; + min_port = *port; + rc = idr_alloc_u32(&qrtr_ports, ipc, &min_port, *port, GFP_ATOMIC); + if (!rc) + *port = min_port; } mutex_unlock(&qrtr_port_lock);