intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: matthew.auld@intel.com
Cc: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [bug report] drm/i915: buddy allocator
Date: Tue, 2 Mar 2021 14:18:48 +0300	[thread overview]
Message-ID: <YD4fGEw/aeme7oye@mwanda> (raw)

[ Sorry, I don't know why Smatch is complaining about two year old code.
  The warning is valid enough, though.  - dan ]

Hello Matthew Auld,

The patch 14d1b9a6247c: "drm/i915: buddy allocator" from Aug 9, 2019,
leads to the following static checker warning:

	drivers/gpu/drm/i915/selftests/i915_buddy.c:169 igt_check_blocks()
	warn: variable dereferenced before check 'block' (see line 126)

drivers/gpu/drm/i915/selftests/i915_buddy.c
   111  static int igt_check_blocks(struct i915_buddy_mm *mm,
   112                              struct list_head *blocks,
   113                              u64 expected_size,
   114                              bool is_contiguous)
   115  {
   116          struct i915_buddy_block *block;
   117          struct i915_buddy_block *prev;
   118          u64 total;
   119          int err = 0;
   120  
   121          block = NULL;
   122          prev = NULL;
   123          total = 0;
   124  
   125          list_for_each_entry(block, blocks, link) {
                                    ^^^^^
"block" is the list iterator so it can't be NULL.

   126                  err = igt_check_block(mm, block);
   127  
   128                  if (!i915_buddy_block_is_allocated(block)) {
   129                          pr_err("block not allocated\n"),
   130                          err = -EINVAL;
   131                  }
   132  
   133                  if (is_contiguous && prev) {
   134                          u64 prev_block_size;
   135                          u64 prev_offset;
   136                          u64 offset;
   137  
   138                          prev_offset = i915_buddy_block_offset(prev);
   139                          prev_block_size = i915_buddy_block_size(mm, prev);
   140                          offset = i915_buddy_block_offset(block);
   141  
   142                          if (offset != (prev_offset + prev_block_size)) {
   143                                  pr_err("block offset mismatch\n");
   144                                  err = -EINVAL;
   145                          }
   146                  }
   147  
   148                  if (err)
   149                          break;
   150  
   151                  total += i915_buddy_block_size(mm, block);
   152                  prev = block;
   153          }
   154  
   155          if (!err) {
   156                  if (total != expected_size) {
   157                          pr_err("size mismatch, expected=%llx, found=%llx\n",
   158                                 expected_size, total);
   159                          err = -EINVAL;
   160                  }
   161                  return err;
   162          }
   163  
   164          if (prev) {
   165                  pr_err("prev block, dump:\n");
   166                  igt_dump_block(mm, prev);
   167          }
   168  
   169          if (block) {
                    ^^^^^
This is impossible.  It's not clear what was intended...

   170                  pr_err("bad block, dump:\n");
   171                  igt_dump_block(mm, block);
   172          }
   173  
   174          return err;
   175  }

regards,
dan carpenter
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

                 reply	other threads:[~2021-03-02 12:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=YD4fGEw/aeme7oye@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.auld@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;
as well as URLs for NNTP newsgroup(s).