media: staging: media: atomisp: Use kmap_local_page() in hmm_store()
authorFabio M. De Francesco <fmdefrancesco@gmail.com>
Wed, 13 Apr 2022 22:55:31 +0000 (23:55 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 8 Jul 2022 16:35:42 +0000 (17:35 +0100)
The use of kmap() is being deprecated in favor of kmap_local_page()
where it is feasible. The same is true for kmap_atomic().

In file pci/hmm/hmm.c, function hmm_store() test if we are in atomic
context and, if so, it calls kmap_atomic(), if not, it calls kmap().

First of all, in_atomic() shouldn't be used in drivers. This macro
cannot always detect atomic context; in particular, it cannot know
about held spinlocks in non-preemptible kernels.

Notwithstanding what it is said above, this code doesn't need to care
whether or not it is executing in atomic context. It can simply use
kmap_local_page() / kunmap_local() that can instead do the mapping /
unmapping regardless of the context.

With kmap_local_page(), the mapping is per thread, CPU local and not
globally visible. Therefore, hmm_store()() is a function where the use
of kmap_local_page() in place of both kmap() and kmap_atomic() is
correctly suited.

Convert the calls of kmap() / kunmap() and kmap_atomic() /
kunmap_atomic() to kmap_local_page() / kunmap_local() and drop the
unnecessary tests which test if the code is in atomic context.

Link: https://lore.kernel.org/linux-media/20220413225531.9425-1-fmdefrancesco@gmail.com
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/atomisp/pci/hmm/hmm.c

index 2b015de..fc6cfe9 100644 (file)
@@ -427,10 +427,7 @@ int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes)
                idx = (virt - bo->start) >> PAGE_SHIFT;
                offset = (virt - bo->start) - (idx << PAGE_SHIFT);
 
-               if (in_atomic())
-                       des = (char *)kmap_atomic(bo->pages[idx]);
-               else
-                       des = (char *)kmap(bo->pages[idx]);
+               des = (char *)kmap_local_page(bo->pages[idx]);
 
                if (!des) {
                        dev_err(atomisp_dev,
@@ -457,14 +454,7 @@ int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes)
 
                clflush_cache_range(des, len);
 
-               if (in_atomic())
-                       /*
-                        * Note: kunmap_atomic requires return addr from
-                        * kmap_atomic, not the page. See linux/highmem.h
-                        */
-                       kunmap_atomic(des - offset);
-               else
-                       kunmap(bo->pages[idx]);
+               kunmap_local(des);
        }
 
        return 0;