public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: luiz.von.dentz@intel.com
Cc: linux-bluetooth@vger.kernel.org
Subject: [bug report] Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg
Date: Wed, 15 Sep 2021 12:25:46 +0300	[thread overview]
Message-ID: <20210915092546.GA4603@kili> (raw)

Hello Luiz Augusto von Dentz,

The patch 81be03e026dc: "Bluetooth: RFCOMM: Replace use of
memcpy_from_msg with bt_skb_sendmmsg" from Sep 3, 2021, leads to the
following
Smatch static checker warning:

	net/bluetooth/rfcomm/sock.c:587 rfcomm_sock_sendmsg()
	warn: passing zero to 'PTR_ERR'

net/bluetooth/rfcomm/sock.c
    556 static int rfcomm_sock_sendmsg(struct socket *sock, struct msghdr *msg,
    557                                size_t len)
    558 {
    559         struct sock *sk = sock->sk;
    560         struct rfcomm_dlc *d = rfcomm_pi(sk)->dlc;
    561         struct sk_buff *skb;
    562         int sent;
    563 
    564         if (test_bit(RFCOMM_DEFER_SETUP, &d->flags))
    565                 return -ENOTCONN;
    566 
    567         if (msg->msg_flags & MSG_OOB)
    568                 return -EOPNOTSUPP;
    569 
    570         if (sk->sk_shutdown & SEND_SHUTDOWN)
    571                 return -EPIPE;
    572 
    573         BT_DBG("sock %p, sk %p", sock, sk);
    574 
    575         lock_sock(sk);
    576 
    577         sent = bt_sock_wait_ready(sk, msg->msg_flags);
    578 
    579         release_sock(sk);
    580 
    581         if (sent)
    582                 return sent;
    583 
    584         skb = bt_skb_sendmmsg(sk, msg, len, d->mtu, RFCOMM_SKB_HEAD_RESERVE,
    585                               RFCOMM_SKB_TAIL_RESERVE);
    586         if (IS_ERR_OR_NULL(skb))

When a function returns both error pointers and NULL then that means
the feature is optional and can be turned off by the user.

	blinking_lights = get_blinking_lights();

We should report the error to the user.

	if (IS_ERR(blinking_lights))
		return PTR_ERR(blinking_lights);

However, some users maybe want a smaller kernel with no blinking lights
so they disable it.  In that case the driver has to check for NULL, and
not print an error message but instead continue as best as possible
without that feature enabled.

The bt_skb_sendmmsg() cannot return NULL.  But if it did return NULL
then PTR_ERR(NULL) is success so that's not right...  All the callers
of bt_skb_sendmmsg() have the same issue.

--> 587                 return PTR_ERR(skb);
    588 
    589         sent = rfcomm_dlc_send(d, skb);
    590         if (sent < 0)
    591                 kfree_skb(skb);
    592 
    593         return sent;
    594 }

regards,
dan carpenter

             reply	other threads:[~2021-09-15  9:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15  9:25 Dan Carpenter [this message]
2021-09-15 18:46 ` [bug report] Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210915092546.GA4603@kili \
    --to=dan.carpenter@oracle.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox