mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Colin Ian King <colin.king@canonical.com>
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Matthew Auld" <matthew.auld@intel.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
	intel-gfx <intel-gfx@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: re: drm/i915/ttm Initialize the ttm device and memory managers
Date: Mon, 12 Jul 2021 16:12:11 +0100	[thread overview]
Message-ID: <161dac7a-5aad-150e-7c14-7bb195ecf30f@canonical.com> (raw)

Hi,

Static analysis with Coverity on linux-next has found a potential issue
in drivers/gpu/drm/i915/selftests/intel_memory_region.c in function
igt_mock_fill - the problematic commit is as follows:

commit d148738923fdb5077089e48ec15555e6008100d0
Author: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Date:   Wed Jun 2 10:38:08 2021 +0200

    drm/i915/ttm Initialize the ttm device and memory managers

The analysis is as follows:


 49 static int igt_mock_fill(void *arg)
 50 {
 51        struct intel_memory_region *mem = arg;
 52        resource_size_t total = resource_size(&mem->region);
 53        resource_size_t page_size;
 54        resource_size_t rem;
 55        unsigned long max_pages;
 56        unsigned long page_num;
 57        LIST_HEAD(objects);
 58        int err = 0;
 59
 60        page_size = mem->chunk_size;
 61        rem = total;
 62 retry:

value_overwrite: Overwriting previous write to max_pages with value from
div64_u64(rem, page_size).

 63        max_pages = div64_u64(rem, page_size);
 64
 65        for_each_prime_number_from(page_num, 1, max_pages) {
 66                resource_size_t size = page_num * page_size;
 67                struct drm_i915_gem_object *obj;
 68
 69                obj = i915_gem_object_create_region(mem, size, 0);
 70                if (IS_ERR(obj)) {
 71                        err = PTR_ERR(obj);
 72                        break;
 73                }
 74
 75                err = i915_gem_object_pin_pages_unlocked(obj);
 76                if (err) {
 77                        i915_gem_object_put(obj);
 78                        break;
 79                }
 80
 81                list_add(&obj->st_link, &objects);
 82                rem -= size;
 83        }
 84
 85        if (err == -ENOMEM)
 86                err = 0;
 87        if (err == -ENXIO) {
 88                if (page_num * page_size <= rem) {
 89                        if (mem->is_range_manager && max_pages > 1) {

Unused value (UNUSED_VALUE)
assigned_value: Assigning value from max_pages >> 1 to max_pages here,
but that stored value is overwritten before it can be used.

 90                                max_pages >>= 1;
 91                                goto retry;
 92                        }
 93

The right shift to max_pages on line 90 is being overwritten on line 64
on the retry.

Colin

             reply	other threads:[~2021-07-12 15:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12 15:12 Colin Ian King [this message]
2021-07-12 16:22 ` Matthew Auld

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=161dac7a-5aad-150e-7c14-7bb195ecf30f@canonical.com \
    --to=colin.king@canonical.com \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.auld@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=thomas.hellstrom@linux.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

all inboxes | Powered by JetHome®