[drm-misc:for-linux-next-fixes 1/1] drivers/gpu/drm/ttm/ttm_resource.c:117:40: warning: suggest parentheses around '&&' within '||'

kernel test robot lkp at intel.com
Thu Jun 22 23:23:20 UTC 2023


tree:   git://anongit.freedesktop.org/drm/drm-misc for-linux-next-fixes
head:   4481913607e58196c48a4fef5e6f45350684ec3c
commit: 4481913607e58196c48a4fef5e6f45350684ec3c [1/1] drm/ttm: fix bulk_move corruption when adding a entry
config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20230623/202306230747.Ws6Fhv2o-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230623/202306230747.Ws6Fhv2o-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp at intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306230747.Ws6Fhv2o-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/build_bug.h:5,
                    from include/linux/init.h:5,
                    from include/linux/io.h:10,
                    from include/linux/iosys-map.h:10,
                    from drivers/gpu/drm/ttm/ttm_resource.c:25:
   drivers/gpu/drm/ttm/ttm_resource.c: In function 'ttm_lru_bulk_move_del':
>> drivers/gpu/drm/ttm/ttm_resource.c:117:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     117 |                      pos->first == res && pos->last == res)) {
         |                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
   include/linux/compiler.h:77:45: note: in definition of macro 'unlikely'
      77 | # define unlikely(x)    __builtin_expect(!!(x), 0)
         |                                             ^


vim +117 drivers/gpu/drm/ttm/ttm_resource.c

  > 25	#include <linux/iosys-map.h>
    26	#include <linux/io-mapping.h>
    27	#include <linux/scatterlist.h>
    28	
    29	#include <drm/ttm/ttm_bo.h>
    30	#include <drm/ttm/ttm_placement.h>
    31	#include <drm/ttm/ttm_resource.h>
    32	
    33	/**
    34	 * ttm_lru_bulk_move_init - initialize a bulk move structure
    35	 * @bulk: the structure to init
    36	 *
    37	 * For now just memset the structure to zero.
    38	 */
    39	void ttm_lru_bulk_move_init(struct ttm_lru_bulk_move *bulk)
    40	{
    41		memset(bulk, 0, sizeof(*bulk));
    42	}
    43	EXPORT_SYMBOL(ttm_lru_bulk_move_init);
    44	
    45	/**
    46	 * ttm_lru_bulk_move_tail - bulk move range of resources to the LRU tail.
    47	 *
    48	 * @bulk: bulk move structure
    49	 *
    50	 * Bulk move BOs to the LRU tail, only valid to use when driver makes sure that
    51	 * resource order never changes. Should be called with &ttm_device.lru_lock held.
    52	 */
    53	void ttm_lru_bulk_move_tail(struct ttm_lru_bulk_move *bulk)
    54	{
    55		unsigned i, j;
    56	
    57		for (i = 0; i < TTM_NUM_MEM_TYPES; ++i) {
    58			for (j = 0; j < TTM_MAX_BO_PRIORITY; ++j) {
    59				struct ttm_lru_bulk_move_pos *pos = &bulk->pos[i][j];
    60				struct ttm_resource_manager *man;
    61	
    62				if (!pos->first)
    63					continue;
    64	
    65				lockdep_assert_held(&pos->first->bo->bdev->lru_lock);
    66				dma_resv_assert_held(pos->first->bo->base.resv);
    67				dma_resv_assert_held(pos->last->bo->base.resv);
    68	
    69				man = ttm_manager_type(pos->first->bo->bdev, i);
    70				list_bulk_move_tail(&man->lru[j], &pos->first->lru,
    71						    &pos->last->lru);
    72			}
    73		}
    74	}
    75	EXPORT_SYMBOL(ttm_lru_bulk_move_tail);
    76	
    77	/* Return the bulk move pos object for this resource */
    78	static struct ttm_lru_bulk_move_pos *
    79	ttm_lru_bulk_move_pos(struct ttm_lru_bulk_move *bulk, struct ttm_resource *res)
    80	{
    81		return &bulk->pos[res->mem_type][res->bo->priority];
    82	}
    83	
    84	/* Move the resource to the tail of the bulk move range */
    85	static void ttm_lru_bulk_move_pos_tail(struct ttm_lru_bulk_move_pos *pos,
    86					       struct ttm_resource *res)
    87	{
    88		if (pos->last != res) {
    89			if (pos->first == res)
    90				pos->first = list_next_entry(res, lru);
    91			list_move(&res->lru, &pos->last->lru);
    92			pos->last = res;
    93		}
    94	}
    95	
    96	/* Add the resource to a bulk_move cursor */
    97	static void ttm_lru_bulk_move_add(struct ttm_lru_bulk_move *bulk,
    98					  struct ttm_resource *res)
    99	{
   100		struct ttm_lru_bulk_move_pos *pos = ttm_lru_bulk_move_pos(bulk, res);
   101	
   102		if (!pos->first) {
   103			pos->first = res;
   104			pos->last = res;
   105		} else {
   106			ttm_lru_bulk_move_pos_tail(pos, res);
   107		}
   108	}
   109	
   110	/* Remove the resource from a bulk_move range */
   111	static void ttm_lru_bulk_move_del(struct ttm_lru_bulk_move *bulk,
   112					  struct ttm_resource *res)
   113	{
   114		struct ttm_lru_bulk_move_pos *pos = ttm_lru_bulk_move_pos(bulk, res);
   115	
   116		if (unlikely(WARN_ON(!pos->first || !pos->last) ||
 > 117			     pos->first == res && pos->last == res)) {
   118			pos->first = NULL;
   119			pos->last = NULL;
   120		} else if (pos->first == res) {
   121			pos->first = list_next_entry(res, lru);
   122		} else if (pos->last == res) {
   123			pos->last = list_prev_entry(res, lru);
   124		} else {
   125			list_move(&res->lru, &pos->last->lru);
   126		}
   127	}
   128	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


More information about the dri-devel mailing list