Skip to content

Commit

Permalink
mm/alloc: remove all unnecessary check for psock/conn
Browse files Browse the repository at this point in the history
Since inet/socket layer already contains sanity checks, so remove unnecessary lower half checks

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao committed Aug 30, 2023
1 parent e064a83 commit e07b819
Show file tree
Hide file tree
Showing 43 changed files with 25 additions and 108 deletions.
3 changes: 0 additions & 3 deletions net/bluetooth/bluetooth_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ static ssize_t bluetooth_l2cap_send(FAR struct socket *psock,
ssize_t ret;

conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

if (!_SS_ISCONNECTED(conn->bc_conn.s_flags))
{
Expand Down Expand Up @@ -491,8 +490,6 @@ static ssize_t bluetooth_send(FAR struct socket *psock, FAR const void *buf,
{
ssize_t ret;

DEBUGASSERT(psock != NULL || buf != NULL);

/* Only SOCK_RAW is supported */

if (psock->s_type == SOCK_RAW)
Expand Down
13 changes: 1 addition & 12 deletions net/bluetooth/bluetooth_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ static void bluetooth_addref(FAR struct socket *psock)
{
FAR struct bluetooth_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
(psock->s_type == SOCK_RAW || psock->s_type == SOCK_CTRL));
DEBUGASSERT(psock->s_type == SOCK_RAW || psock->s_type == SOCK_CTRL);

conn = psock->s_conn;
DEBUGASSERT(conn->bc_crefs > 0 && conn->bc_crefs < 255);
Expand Down Expand Up @@ -250,9 +249,7 @@ static int bluetooth_connect(FAR struct socket *psock,
FAR struct sockaddr_l2 *btaddr;
int ret = OK;

DEBUGASSERT(psock != NULL || addr != NULL);
conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

/* Verify the address family */

Expand Down Expand Up @@ -308,8 +305,6 @@ static int bluetooth_connect(FAR struct socket *psock,
static int bluetooth_bind(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen)
{
DEBUGASSERT(psock != NULL && addr != NULL);

/* Verify that a valid address has been provided */

if (addr->sa_family != AF_BLUETOOTH)
Expand Down Expand Up @@ -521,10 +516,7 @@ static int bluetooth_getsockname(FAR struct socket *psock,
FAR struct sockaddr_l2 tmp;
socklen_t copylen;

DEBUGASSERT(psock != NULL && addr != NULL && addrlen != NULL);

conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

/* Create a copy of the full address on the stack */

Expand Down Expand Up @@ -583,15 +575,12 @@ static int bluetooth_getpeername(FAR struct socket *psock,
FAR struct sockaddr_l2 tmp;
socklen_t copylen;

DEBUGASSERT(psock != NULL && addr != NULL && addrlen != NULL);

if (psock->s_proto != BTPROTO_L2CAP)
{
return -EPFNOSUPPORT;
}

conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

/* Create a copy of the full address on the stack */

Expand Down
3 changes: 1 addition & 2 deletions net/can/can_getsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ int can_getsockopt(FAR struct socket *psock, int level, int option,
FAR struct can_conn_s *conn;
int ret = OK;

DEBUGASSERT(psock != NULL && value != NULL && value_len != NULL &&
psock->s_conn != NULL);
DEBUGASSERT(value != NULL && value_len != NULL);
conn = psock->s_conn;

#ifdef CONFIG_NET_TIMESTAMP
Expand Down
2 changes: 0 additions & 2 deletions net/can/can_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,6 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
struct can_recvfrom_s state;
int ret;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);

conn = psock->s_conn;

if (psock->s_type != SOCK_RAW)
Expand Down
1 change: 0 additions & 1 deletion net/can/can_setsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ int can_setsockopt(FAR struct socket *psock, int level, int option,
int ret = OK;
int count = 0;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
DEBUGASSERT(value_len == 0 || value != NULL);

conn = psock->s_conn;
Expand Down
5 changes: 1 addition & 4 deletions net/can/can_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ static void can_addref(FAR struct socket *psock)
{
FAR struct can_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);

conn = psock->s_conn;
DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255);
conn->crefs++;
Expand Down Expand Up @@ -312,7 +310,7 @@ static int can_bind(FAR struct socket *psock,
{
FAR struct sockaddr_can *canaddr;
FAR struct can_conn_s *conn;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && addr != NULL &&
DEBUGASSERT(addr != NULL &&
addrlen >= sizeof(struct sockaddr_can));

/* Save the address information in the connection structure */
Expand Down Expand Up @@ -365,7 +363,6 @@ static int can_poll_local(FAR struct socket *psock, FAR struct pollfd *fds,
pollevent_t eventset = 0;
int ret = OK;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = psock->s_conn;
info = conn->pollinfo;

Expand Down
1 change: 0 additions & 1 deletion net/icmp/icmp_netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ static uint16_t icmp_poll_eventhandler(FAR struct net_driver_s *dev,
*/

psock = info->psock;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = psock->s_conn;
if (dev != conn->dev)
{
Expand Down
3 changes: 1 addition & 2 deletions net/icmp/icmp_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ static uint16_t recvfrom_eventhandler(FAR struct net_driver_s *dev,
}

psock = pstate->recv_sock;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);

/* Check if we have just received a ICMP ECHO reply. */

Expand Down Expand Up @@ -295,7 +294,7 @@ ssize_t icmp_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,

/* Some sanity checks */

DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
DEBUGASSERT(buf != NULL);

if (len < ICMP_HDRLEN)
{
Expand Down
2 changes: 1 addition & 1 deletion net/icmp/icmp_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ ssize_t icmp_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,

/* Some sanity checks */

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
buf != NULL && to != NULL);

if (len < ICMP_HDRLEN || tolen < sizeof(struct sockaddr_in))
Expand Down
3 changes: 0 additions & 3 deletions net/icmp/icmp_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ static void icmp_addref(FAR struct socket *psock)
{
FAR struct icmp_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);

conn = psock->s_conn;
DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255);
conn->crefs++;
Expand Down Expand Up @@ -254,7 +252,6 @@ static int icmp_close(FAR struct socket *psock)
{
FAR struct icmp_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = psock->s_conn;

/* Is this the last reference to the connection structure (there could be\
Expand Down
1 change: 0 additions & 1 deletion net/icmpv6/icmpv6_netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ static uint16_t icmpv6_poll_eventhandler(FAR struct net_driver_s *dev,
*/

psock = info->psock;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = psock->s_conn;
if (dev != conn->dev)
{
Expand Down
3 changes: 1 addition & 2 deletions net/icmpv6/icmpv6_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ static uint16_t recvfrom_eventhandler(FAR struct net_driver_s *dev,
}

psock = pstate->recv_sock;
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);

/* Check if we have just received a ICMPv6 message. */

Expand Down Expand Up @@ -309,7 +308,7 @@ ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,

/* Some sanity checks */

DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
DEBUGASSERT(buf != NULL);

if (len < ICMPv6_HDRLEN)
{
Expand Down
2 changes: 1 addition & 1 deletion net/icmpv6/icmpv6_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ ssize_t icmpv6_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,

/* Some sanity checks */

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
buf != NULL && to != NULL);

if (len < ICMPv6_HDRLEN || tolen < sizeof(struct sockaddr_in6))
Expand Down
3 changes: 0 additions & 3 deletions net/icmpv6/icmpv6_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ static void icmpv6_addref(FAR struct socket *psock)
{
FAR struct icmpv6_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);

conn = psock->s_conn;
DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255);
conn->crefs++;
Expand Down Expand Up @@ -255,7 +253,6 @@ static int icmpv6_close(FAR struct socket *psock)
{
FAR struct icmpv6_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = psock->s_conn;

/* Is this the last reference to the connection structure (there could be\
Expand Down
4 changes: 0 additions & 4 deletions net/ieee802154/ieee802154_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ static void ieee802154_meta_data(FAR struct radio_driver_s *radio,
meta != NULL);

psock = pstate->is_sock;
DEBUGASSERT(psock->s_conn != NULL);

conn = psock->s_conn;
srcaddr = &conn->laddr;
destaddr = &pstate->is_destaddr;
Expand Down Expand Up @@ -565,9 +563,7 @@ static ssize_t ieee802154_send(FAR struct socket *psock, FAR const void *buf,
FAR struct ieee802154_conn_s *conn;
ssize_t ret;

DEBUGASSERT(psock != NULL || buf != NULL);
conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

/* Only SOCK_DGRAM is supported (because the MAC header is stripped) */

Expand Down
13 changes: 1 addition & 12 deletions net/ieee802154/ieee802154_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ static void ieee802154_addref(FAR struct socket *psock)
{
FAR struct ieee802154_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
(psock->s_type == SOCK_DGRAM || psock->s_type == SOCK_CTRL));
DEBUGASSERT(psock->s_type == SOCK_DGRAM || psock->s_type == SOCK_CTRL);

conn = psock->s_conn;
DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255);
Expand Down Expand Up @@ -247,9 +246,7 @@ static int ieee802154_connect(FAR struct socket *psock,
FAR struct sockaddr_ieee802154_s *ieeeaddr;
int ret = OK;

DEBUGASSERT(psock != NULL || addr != NULL);
conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

/* Verify the address family */

Expand Down Expand Up @@ -302,8 +299,6 @@ static int ieee802154_bind(FAR struct socket *psock,
FAR struct ieee802154_conn_s *conn;
FAR struct radio_driver_s *radio;

DEBUGASSERT(psock != NULL && addr != NULL);

/* Verify that a valid address has been provided */

if (addr->sa_family != AF_IEEE802154 ||
Expand Down Expand Up @@ -400,10 +395,7 @@ static int ieee802154_getsockname(FAR struct socket *psock,
FAR struct sockaddr_ieee802154_s tmp;
socklen_t copylen;

DEBUGASSERT(psock != NULL && addr != NULL && addrlen != NULL);

conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

/* Create a copy of the full address on the stack */

Expand Down Expand Up @@ -462,10 +454,7 @@ static int ieee802154_getpeername(FAR struct socket *psock,
FAR struct sockaddr_ieee802154_s tmp;
socklen_t copylen;

DEBUGASSERT(psock != NULL && addr != NULL && addrlen != NULL);

conn = psock->s_conn;
DEBUGASSERT(conn != NULL);

/* Create a copy of the full address on the stack */

Expand Down
1 change: 0 additions & 1 deletion net/local/local_accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,

/* Some sanity checks */

DEBUGASSERT(psock && psock->s_conn);
DEBUGASSERT(newsock && !newsock->s_conn);

/* Is the socket a stream? */
Expand Down
2 changes: 1 addition & 1 deletion net/local/local_bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int psock_local_bind(FAR struct socket *psock,
FAR const struct sockaddr_un *unaddr =
(FAR const struct sockaddr_un *)addr;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
unaddr != NULL && unaddr->sun_family == AF_LOCAL);

if (addrlen <= sizeof(sa_family_t) + 1)
Expand Down
1 change: 0 additions & 1 deletion net/local/local_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ int psock_local_connect(FAR struct socket *psock,
struct stat buf;
int ret;

DEBUGASSERT(psock && psock->s_conn);
client = psock->s_conn;

if (client->lc_state == LOCAL_STATE_ACCEPT ||
Expand Down
2 changes: 1 addition & 1 deletion net/local/local_recvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
FAR void *buf = msg->msg_iov->iov_base;
size_t len = msg->msg_iov->iov_len;

DEBUGASSERT(psock && psock->s_conn && buf);
DEBUGASSERT(buf);

/* Check for a stream socket */

Expand Down
2 changes: 1 addition & 1 deletion net/local/local_sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static ssize_t local_send(FAR struct socket *psock,

/* Local TCP packet send */

DEBUGASSERT(psock && psock->s_conn && buf);
DEBUGASSERT(buf);
peer = psock->s_conn;

/* Verify that this is a connected peer socket and that it has
Expand Down
10 changes: 5 additions & 5 deletions net/local/local_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static void local_addref(FAR struct socket *psock)
{
FAR struct local_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
psock->s_domain == PF_LOCAL);

conn = psock->s_conn;
Expand Down Expand Up @@ -368,7 +368,7 @@ static int local_getsockname(FAR struct socket *psock,
FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
FAR struct local_conn_s *conn;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
unaddr != NULL && addrlen != NULL);

if (*addrlen < sizeof(sa_family_t))
Expand Down Expand Up @@ -467,7 +467,7 @@ static int local_getpeername(FAR struct socket *psock,
FAR struct local_conn_s *conn;
FAR struct local_conn_s *peer;

DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
unaddr != NULL && addrlen != NULL);

if (*addrlen < sizeof(sa_family_t))
Expand Down Expand Up @@ -573,7 +573,7 @@ static int local_getpeername(FAR struct socket *psock,
static int local_getsockopt(FAR struct socket *psock, int level, int option,
FAR void *value, FAR socklen_t *value_len)
{
DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
psock->s_domain == PF_LOCAL);

#ifdef CONFIG_NET_LOCAL_SCM
Expand Down Expand Up @@ -1018,7 +1018,7 @@ static int local_socketpair(FAR struct socket *psocks[2])

static int local_shutdown(FAR struct socket *psock, int how)
{
DEBUGASSERT(psock != NULL && psock->s_conn != NULL &&
DEBUGASSERT(
psock->s_domain == PF_LOCAL);

switch (psock->s_type)
Expand Down
Loading

0 comments on commit e07b819

Please sign in to comment.