All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild@lists.01.org
Subject: Re: [rdma-rdma:wip/jgg-for-next 198/203] drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'
Date: Mon, 15 Feb 2021 17:16:33 +0300	[thread overview]
Message-ID: <20210215141633.GD2222@kadam> (raw)
In-Reply-To: <CAMGffEmbY1FMOHQsKeUK-f=JT6QFGE44Mmu=OFttEJVanbeXvg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6079 bytes --]

On Mon, Feb 15, 2021 at 03:02:32PM +0100, Jinpu Wang wrote:
> On Mon, Feb 15, 2021 at 2:58 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > On Mon, Feb 15, 2021 at 02:03:31PM +0100, Jinpu Wang wrote:
> > > Hi, Dan,
> > >
> > > On Mon, Feb 15, 2021 at 1:44 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > > >
> > > > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git   wip/jgg-for-next
> > > > head:   c88b31c46cefe50f524a1ad3deaf1599bc9ee2e6
> > > > commit: f0751419d3a15fb06d9b7d9435312472c3cb122d [198/203] RDMA/rtrs: Only allow addition of path to an already established session
> > > > config: ia64-randconfig-m031-20210209 (attached as .config)
> > > > compiler: ia64-linux-gcc (GCC) 9.3.0
> > > >
> > > > If you fix the issue, kindly add following tag as appropriate
> > > > Reported-by: kernel test robot <lkp@intel.com>
> > > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > >
> > > > smatch warnings:
> > > > drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'
> > > >
> > > > vim +/PTR_ERR +1805 drivers/infiniband/ulp/rtrs/rtrs-srv.c
> > > >
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1760  static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1761                                const struct rtrs_msg_conn_req *msg,
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1762                                size_t len)
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1763  {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1764          struct rtrs_srv_ctx *ctx = cm_id->context;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1765          struct rtrs_srv_sess *sess;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1766          struct rtrs_srv *srv;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1767
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1768          u16 version, con_num, cid;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1769          u16 recon_cnt;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1770          int err;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1771
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1772          if (len < sizeof(*msg)) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1773                  pr_err("Invalid RTRS connection request\n");
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1774                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1775          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1776          if (le16_to_cpu(msg->magic) != RTRS_MAGIC) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1777                  pr_err("Invalid RTRS magic\n");
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1778                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1779          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1780          version = le16_to_cpu(msg->version);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1781          if (version >> 8 != RTRS_PROTO_VER_MAJOR) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1782                  pr_err("Unsupported major RTRS version: %d, expected %d\n",
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1783                         version >> 8, RTRS_PROTO_VER_MAJOR);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1784                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1785          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1786          con_num = le16_to_cpu(msg->cid_num);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1787          if (con_num > 4096) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1788                  /* Sanity check */
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1789                  pr_err("Too many connections requested: %d\n", con_num);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1790                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1791          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1792          cid = le16_to_cpu(msg->cid);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1793          if (cid >= con_num) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1794                  /* Sanity check */
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1795                  pr_err("Incorrect cid: %d >= %d\n", cid, con_num);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1796                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1797          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1798          recon_cnt = le16_to_cpu(msg->recon_cnt);
> > > > f0751419d3a15f Md Haris Iqbal 2021-02-12  1799          srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1800          /*
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1801           * "refcount == 0" happens if a previous thread calls get_or_create_srv
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1802           * allocate srv, but chunks of srv are not allocated yet.
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1803           */
> > > > f0751419d3a15f Md Haris Iqbal 2021-02-12  1804          if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
> > > > f0751419d3a15f Md Haris Iqbal 2021-02-12 @1805                  err = PTR_ERR(srv);
> > > >
> > > > It's not 100% clear to me that an error code is required when
> > > > refcount_read() is zero.  Maybe "err = 0;" is okay in that situation?
> > > I don't see how srv can be zero
> >
> > The cross function database was probably out of date.
> 
> Thanks for the hint, just curious where is the cross-function
> database? is it auto-generated by gcc during compile?

This is a Smatch warning.

https://www.spinics.net/lists/smatch/msg00568.html

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kbuild-all@lists.01.org
Subject: Re: [rdma-rdma:wip/jgg-for-next 198/203] drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'
Date: Mon, 15 Feb 2021 17:16:33 +0300	[thread overview]
Message-ID: <20210215141633.GD2222@kadam> (raw)
In-Reply-To: <CAMGffEmbY1FMOHQsKeUK-f=JT6QFGE44Mmu=OFttEJVanbeXvg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6079 bytes --]

On Mon, Feb 15, 2021 at 03:02:32PM +0100, Jinpu Wang wrote:
> On Mon, Feb 15, 2021 at 2:58 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > On Mon, Feb 15, 2021 at 02:03:31PM +0100, Jinpu Wang wrote:
> > > Hi, Dan,
> > >
> > > On Mon, Feb 15, 2021 at 1:44 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > > >
> > > > tree:   https://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma.git   wip/jgg-for-next
> > > > head:   c88b31c46cefe50f524a1ad3deaf1599bc9ee2e6
> > > > commit: f0751419d3a15fb06d9b7d9435312472c3cb122d [198/203] RDMA/rtrs: Only allow addition of path to an already established session
> > > > config: ia64-randconfig-m031-20210209 (attached as .config)
> > > > compiler: ia64-linux-gcc (GCC) 9.3.0
> > > >
> > > > If you fix the issue, kindly add following tag as appropriate
> > > > Reported-by: kernel test robot <lkp@intel.com>
> > > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > >
> > > > smatch warnings:
> > > > drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR'
> > > >
> > > > vim +/PTR_ERR +1805 drivers/infiniband/ulp/rtrs/rtrs-srv.c
> > > >
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1760  static int rtrs_rdma_connect(struct rdma_cm_id *cm_id,
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1761                                const struct rtrs_msg_conn_req *msg,
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1762                                size_t len)
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1763  {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1764          struct rtrs_srv_ctx *ctx = cm_id->context;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1765          struct rtrs_srv_sess *sess;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1766          struct rtrs_srv *srv;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1767
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1768          u16 version, con_num, cid;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1769          u16 recon_cnt;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1770          int err;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1771
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1772          if (len < sizeof(*msg)) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1773                  pr_err("Invalid RTRS connection request\n");
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1774                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1775          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1776          if (le16_to_cpu(msg->magic) != RTRS_MAGIC) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1777                  pr_err("Invalid RTRS magic\n");
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1778                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1779          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1780          version = le16_to_cpu(msg->version);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1781          if (version >> 8 != RTRS_PROTO_VER_MAJOR) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1782                  pr_err("Unsupported major RTRS version: %d, expected %d\n",
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1783                         version >> 8, RTRS_PROTO_VER_MAJOR);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1784                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1785          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1786          con_num = le16_to_cpu(msg->cid_num);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1787          if (con_num > 4096) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1788                  /* Sanity check */
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1789                  pr_err("Too many connections requested: %d\n", con_num);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1790                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1791          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1792          cid = le16_to_cpu(msg->cid);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1793          if (cid >= con_num) {
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1794                  /* Sanity check */
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1795                  pr_err("Incorrect cid: %d >= %d\n", cid, con_num);
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1796                  goto reject_w_econnreset;
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1797          }
> > > > 9cb837480424e7 Jack Wang      2020-05-11  1798          recon_cnt = le16_to_cpu(msg->recon_cnt);
> > > > f0751419d3a15f Md Haris Iqbal 2021-02-12  1799          srv = get_or_create_srv(ctx, &msg->paths_uuid, msg->first_conn);
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1800          /*
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1801           * "refcount == 0" happens if a previous thread calls get_or_create_srv
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1802           * allocate srv, but chunks of srv are not allocated yet.
> > > > d715ff8acbd587 Guoqing Jiang  2020-10-23  1803           */
> > > > f0751419d3a15f Md Haris Iqbal 2021-02-12  1804          if (IS_ERR(srv) || refcount_read(&srv->refcount) == 0) {
> > > > f0751419d3a15f Md Haris Iqbal 2021-02-12 @1805                  err = PTR_ERR(srv);
> > > >
> > > > It's not 100% clear to me that an error code is required when
> > > > refcount_read() is zero.  Maybe "err = 0;" is okay in that situation?
> > > I don't see how srv can be zero
> >
> > The cross function database was probably out of date.
> 
> Thanks for the hint, just curious where is the cross-function
> database? is it auto-generated by gcc during compile?

This is a Smatch warning.

https://www.spinics.net/lists/smatch/msg00568.html

regards,
dan carpenter

       reply	other threads:[~2021-02-15 14:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAMGffEmbY1FMOHQsKeUK-f=JT6QFGE44Mmu=OFttEJVanbeXvg@mail.gmail.com>
2021-02-15 14:16 ` Dan Carpenter [this message]
2021-02-15 14:16   ` [rdma-rdma:wip/jgg-for-next 198/203] drivers/infiniband/ulp/rtrs/rtrs-srv.c:1805 rtrs_rdma_connect() warn: passing zero to 'PTR_ERR' Dan Carpenter
     [not found] <CAMGffEm3ZbPxXzERHLogitw9oz_UK88KE+SZSCy4x1PdvquDZw@mail.gmail.com>
2021-02-15 13:57 ` Dan Carpenter
2021-02-15 13:57   ` Dan Carpenter
2021-02-16 18:58   ` Jason Gunthorpe
2021-02-15 12:44 Dan Carpenter
2021-02-15 12:44 ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2021-02-12 21:28 kernel test robot

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=20210215141633.GD2222@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=kbuild@lists.01.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.