Skip to contentSkip to conversation

staging: media: atomisp: cleanup pci/hmm/ code

PATCH In review Nikolay Kulikov 2 participants 7 messages Aug 14 – Aug 17

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover staging: media: atomisp: cleanup pci/hmm/ code

This series removes unused functions and replaces obscure variable-checking macros with clear conditional statements.

Changes in v4:
- In commit 1, include the removal of the static 'hmm_bo_vm_ops' structure and the hmm_bo_vm_open() and hmm_bo_vm_close() functions (whose addresses are stored in that structure), as they have also become unused and are triggering compiler warinigs (I removed Andy Shevchenko's Rb tag because of this change).
- Add the Rb tag (commit 3).
- Add the base commit hash.
- Add links to v1/v2/v3.
Changes in v3:
- Split the last patch into two (inlining macros and removing the file).
- Replace variable initialization with assignment, followed immediately by a check.
Changes in v2:
- Squashed the function removals in pci/hmm/hmm.c and pci/hmm/hmm_bo.c into a single commit.
- Add commits to cleanup macros from include/hmm/hmm_common.h, as suggested by Andy Shevchenko.

v3: https://lore.kernel.org/linux-staging/[email protected]/
v2: https://lore.kernel.org/linux-staging/[email protected]/
v1: https://lore.kernel.org/linux-staging/[email protected]/

---
Nikolay Kulikov (5):
staging: media: atomisp: remove unused functions from pci/hmm/
staging: media: atomisp: inline macros for checking the bo/bodev pointer
staging: media: atomisp: inline the check_bo_status_*() macros
staging: media: atomisp: inline the var_equal_return*() macros
staging: media: atomisp: remove hmm/hmm_common.h file

 drivers/staging/media/atomisp/include/hmm/hmm.h    |  17 --
 drivers/staging/media/atomisp/include/hmm/hmm_bo.h |  46 ----
 .../staging/media/atomisp/include/hmm/hmm_common.h |  60 -----
 drivers/staging/media/atomisp/pci/hmm/hmm.c        |  41 ----
 drivers/staging/media/atomisp/pci/hmm/hmm_bo.c     | 272 ++++++++-------------
 5 files changed, 100 insertions(+), 336 deletions(-)

---
base-commit: cb08dcd0a896c3ac8073a57296f2377b106c35b4
change-id: 20260813-atomisp_remove_hmm-407662efafaa

Best regards,

Signature · 1 line
Nikolay Kulikov <[email protected]>
#1 lore raw

PATCH v4 1/5 staging: media: atomisp: remove unused functions from pci/hmm/

These functions are declared and defined but are not called anywhere.

---
 drivers/staging/media/atomisp/include/hmm/hmm.h    |  16 ---
 drivers/staging/media/atomisp/include/hmm/hmm_bo.h |  19 ---
 drivers/staging/media/atomisp/pci/hmm/hmm.c        |  41 ------
 drivers/staging/media/atomisp/pci/hmm/hmm_bo.c     | 139 ---------------------
 4 files changed, 215 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm.h +0 -16
index a7aef27f54de..6bda02b9ff85 100644
@@ -32,12 +32,6 @@ void hmm_free(ia_css_ptr ptr);
 int hmm_load(ia_css_ptr virt, void *data, unsigned int bytes);
 int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes);
 int hmm_set(ia_css_ptr virt, int c, unsigned int bytes);
-int hmm_flush(ia_css_ptr virt, unsigned int bytes);
-
-/*
- * get kernel memory physical address from ISP virtual address.
- */
-phys_addr_t hmm_virt_to_phys(ia_css_ptr virt);
 
 /*
  * map ISP memory starts with virt to kernel virtual address
@@ -55,16 +49,6 @@ void hmm_vunmap(ia_css_ptr virt);
  */
 void hmm_flush_vmap(ia_css_ptr virt);
 
-/*
- * map ISP memory starts with virt to specific vma.
- *
- * used for mmap operation.
- *
- * virt must be the start address of ISP memory (return by hmm_alloc),
- * do not pass any other address.
- */
-int hmm_mmap(struct vm_area_struct *vma, ia_css_ptr virt);
-
 extern struct hmm_bo_device bo_device;
 
 #endif
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +0 -19
index e09ac29ac43d..ba3c582a0f89 100644
@@ -205,7 +205,6 @@ int hmm_bo_page_allocated(struct hmm_buffer_object *bo);
  */
 int hmm_bo_bind(struct hmm_buffer_object *bo);
 void hmm_bo_unbind(struct hmm_buffer_object *bo);
-int hmm_bo_binded(struct hmm_buffer_object *bo);
 
 /*
  * vmap buffer object's pages to contiguous kernel virtual address.
@@ -224,17 +223,6 @@ void hmm_bo_flush_vmap(struct hmm_buffer_object *bo);
  */
 void hmm_bo_vunmap(struct hmm_buffer_object *bo);
 
-/*
- * mmap the bo's physical pages to specific vma.
- *
- * vma's address space size must be the same as bo's size,
- * otherwise it will return -EINVAL.
- *
- * vma->vm_flags will be set to (VM_RESERVED | VM_IO).
- */
-int hmm_bo_mmap(struct vm_area_struct *vma,
-		struct hmm_buffer_object *bo);
-
 /*
  * find the buffer object by its virtual address vaddr.
  * return NULL if no such buffer object found.
@@ -251,11 +239,4 @@ struct hmm_buffer_object *hmm_bo_device_search_start(
 struct hmm_buffer_object *hmm_bo_device_search_in_range(
     struct hmm_bo_device *bdev, ia_css_ptr vaddr);
 
-/*
- * find the buffer object with kernel virtual address vaddr.
- * return NULL if no such buffer object found.
- */
-struct hmm_buffer_object *hmm_bo_device_search_vmap_start(
-    struct hmm_bo_device *bdev, const void *vaddr);
-
 #endif
drivers/staging/media/atomisp/pci/hmm/hmm.c +0 -41

53 lines not on this page · raw message

drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +0 -139

154 lines not on this page · raw message

Signature · 1 line
2.55.0
#2 lore raw

PATCH v4 2/5 staging: media: atomisp: inline macros for checking the bo/bodev pointer

In reply to Nikolay Kulikov

These macros perform a pointer check. Replace it with direct conditional expressions to simplify the code.

---
 drivers/staging/media/atomisp/include/hmm/hmm_bo.h | 14 ----
 .../staging/media/atomisp/include/hmm/hmm_common.h |  6 --
 drivers/staging/media/atomisp/pci/hmm/hmm_bo.c     | 96 +++++++++++++++++-----
 3 files changed, 76 insertions(+), 40 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +0 -14
index ba3c582a0f89..e974ab5ca2fc 100644
@@ -19,14 +19,6 @@
 #include "hmm/hmm_common.h"
 #include "ia_css_types.h"
 
-#define	check_bodev_null_return(bdev, exp)	\
-		check_null_return(bdev, exp, \
-			"NULL hmm_bo_device.\n")
-
-#define	check_bodev_null_return_void(bdev)	\
-		check_null_return_void(bdev, \
-			"NULL hmm_bo_device.\n")
-
 #define	check_bo_status_yes_goto(bo, _status, label) \
 	var_not_equal_goto((bo->status & (_status)), (_status), \
 			label, \
@@ -48,12 +40,6 @@
 #define	kref_to_hmm_bo(kref_ptr)	\
 	list_entry((kref_ptr), struct hmm_buffer_object, kref)
 
-#define	check_bo_null_return(bo, exp)	\
-	check_null_return(bo, exp, "NULL hmm buffer object.\n")
-
-#define	check_bo_null_return_void(bo)	\
-	check_null_return_void(bo, "NULL hmm buffer object.\n")
-
 #define	ISP_VM_START	0x0
 #define	ISP_VM_SIZE	(0x7FFFFFFF)	/* 2G address space */
 #define	ISP_PTR_NULL	NULL
drivers/staging/media/atomisp/include/hmm/hmm_common.h +0 -6
index b251e96cc19d..f215130e5e17 100644
@@ -51,10 +51,4 @@
 		} \
 	} while (0)
 
-#define	check_null_return(ptr, exp, fmt, arg ...)	\
-		var_equal_return(ptr, NULL, exp, fmt, ## arg)
-
-#define	check_null_return_void(ptr, fmt, arg ...)	\
-		var_equal_return_void(ptr, NULL, fmt, ## arg)
-
 #endif
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +76 -20

206 lines not on this page · raw message

Signature · 1 line
2.55.0
#3 lore raw

PATCH v4 3/5 staging: media: atomisp: inline the check_bo_status_*() macros

In reply to Nikolay Kulikov

These macros check a bit in the bo->status field. Replace them with conditional expressions to make the code clearer.

---
 drivers/staging/media/atomisp/include/hmm/hmm_bo.h | 12 ---------
 .../staging/media/atomisp/include/hmm/hmm_common.h | 18 -------------
 drivers/staging/media/atomisp/pci/hmm/hmm_bo.c     | 30 ++++++++++++++--------
 3 files changed, 20 insertions(+), 40 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +0 -12
index e974ab5ca2fc..69cf490bd88c 100644
@@ -19,18 +19,6 @@
 #include "hmm/hmm_common.h"
 #include "ia_css_types.h"
 
-#define	check_bo_status_yes_goto(bo, _status, label) \
-	var_not_equal_goto((bo->status & (_status)), (_status), \
-			label, \
-			"HMM buffer status not contain %s.\n", \
-			#_status)
-
-#define	check_bo_status_no_goto(bo, _status, label) \
-	var_equal_goto((bo->status & (_status)), (_status), \
-			label, \
-			"HMM buffer status contains %s.\n", \
-			#_status)
-
 #define rbtree_node_to_hmm_bo(root_node)	\
 	container_of((root_node), struct hmm_buffer_object, node)
 
drivers/staging/media/atomisp/include/hmm/hmm_common.h +0 -18
index f215130e5e17..c406fe8b1345 100644
@@ -33,22 +33,4 @@
 		} \
 	} while (0)
 
-#define	var_equal_goto(var1, var2, label, fmt, arg ...)	\
-	do { \
-		if ((var1) == (var2)) { \
-			dev_err(atomisp_dev, \
-			fmt, ## arg); \
-			goto label;\
-		} \
-	} while (0)
-
-#define	var_not_equal_goto(var1, var2, label, fmt, arg ...)	\
-	do { \
-		if ((var1) != (var2)) { \
-			dev_err(atomisp_dev, \
-			fmt, ## arg); \
-			goto label;\
-		} \
-	} while (0)
-
 #endif
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +20 -10
index 9b29b6381abf..46ee077026b3 100644
@@ -687,7 +687,10 @@ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo,
 	}
 
 	mutex_lock(&bo->mutex);
-	check_bo_status_no_goto(bo, HMM_BO_PAGE_ALLOCED, status_err);
+	if (bo->status & HMM_BO_PAGE_ALLOCED) {
+		dev_err(atomisp_dev, "HMM buffer status contains HMM_BO_PAGE_ALLOCED.\n");
+		goto status_err;
+	}
 
 	bo->pages = kzalloc_objs(struct page *, bo->pgnr);
 	if (unlikely(!bo->pages)) {
@@ -738,7 +741,10 @@ void hmm_bo_free_pages(struct hmm_buffer_object *bo)
 
 	mutex_lock(&bo->mutex);
 
-	check_bo_status_yes_goto(bo, HMM_BO_PAGE_ALLOCED, status_err2);
+	if (!(bo->status & HMM_BO_PAGE_ALLOCED)) {
+		dev_err(atomisp_dev, "HMM buffer status not contain HMM_BO_PAGE_ALLOCED.\n");
+		goto status_err2;
+	}
 
 	/* clear the flag anyway. */
 	bo->status &= (~HMM_BO_PAGE_ALLOCED);
@@ -788,11 +794,15 @@ int hmm_bo_bind(struct hmm_buffer_object *bo)
 
 	mutex_lock(&bo->mutex);
 
-	check_bo_status_yes_goto(bo,
-				 HMM_BO_PAGE_ALLOCED | HMM_BO_ALLOCED,
-				 status_err1);
+	if (!(bo->status & (HMM_BO_PAGE_ALLOCED | HMM_BO_ALLOCED))) {
+		dev_err(atomisp_dev, "HMM buffer status not contain HMM_BO_PAGE_ALLOCED | HMM_BO_ALLOCED.\n");
+		goto status_err1;
+	}
 
-	check_bo_status_no_goto(bo, HMM_BO_BINDED, status_err2);
+	if (bo->status & HMM_BO_BINDED) {
+		dev_err(atomisp_dev, "HMM buffer status contains HMM_BO_BINDED.\n");
+		goto status_err2;
+	}
 
 	bdev = bo->bdev;
 
@@ -868,10 +878,10 @@ void hmm_bo_unbind(struct hmm_buffer_object *bo)
 
 	mutex_lock(&bo->mutex);
 
-	check_bo_status_yes_goto(bo,
-				 HMM_BO_PAGE_ALLOCED |
-				 HMM_BO_ALLOCED |
-				 HMM_BO_BINDED, status_err);
+	if (!(bo->status & (HMM_BO_PAGE_ALLOCED | HMM_BO_ALLOCED | HMM_BO_BINDED))) {
+		dev_err(atomisp_dev, "HMM buffer status not contain HMM_BO_PAGE_ALLOCED | HMM_BO_ALLOCED | HMM_BO_BINDED.\n");
+		goto status_err;
+	}
 
 	bdev = bo->bdev;
 
Signature · 1 line
2.55.0
#4 lore raw

PATCH v4 4/5 staging: media: atomisp: inline the var_equal_return*() macros

In reply to Nikolay Kulikov

These macros check the passed variables for equality, hiding the 'if' and 'return' statements; replace them with a standard conditional to simplify the code.

---
 .../staging/media/atomisp/include/hmm/hmm_common.h   | 20 --------------------
 drivers/staging/media/atomisp/pci/hmm/hmm_bo.c       |  6 ++++--
 2 files changed, 4 insertions(+), 22 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm_common.h +0 -20
index c406fe8b1345..029620347302 100644
@@ -12,25 +12,5 @@
 
 #define	HMM_BO_NAME	"HMM"
 
-/*
- * some common use micros
- */
-#define	var_equal_return(var1, var2, exp, fmt, arg ...)	\
-	do { \
-		if ((var1) == (var2)) { \
-			dev_err(atomisp_dev, \
-			fmt, ## arg); \
-			return exp;\
-		} \
-	} while (0)
-
-#define	var_equal_return_void(var1, var2, fmt, arg ...)	\
-	do { \
-		if ((var1) == (var2)) { \
-			dev_err(atomisp_dev, \
-			fmt, ## arg); \
-			return;\
-		} \
-	} while (0)
 
 #endif
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +4 -2
index 46ee077026b3..7d0ef0f9eec8 100644
@@ -396,8 +396,10 @@ struct hmm_buffer_object *hmm_bo_alloc(struct hmm_bo_device *bdev,
 	}
 
 	root = &bdev->free_rbtree;
-	var_equal_return(hmm_bo_device_inited(bdev), 0, NULL,
-			 "hmm_bo_device not inited yet.\n");
+	if (!hmm_bo_device_inited(bdev)) {
+		dev_err(atomisp_dev, "hmm_bo_device not inited yet.\n");
+		return NULL;
+	}
 
 	if (pgnr == 0) {
 		dev_err(atomisp_dev, "0 size buffer is not allowed.\n");
Signature · 1 line
2.55.0
#5 lore raw

PATCH v4 5/5 staging: media: atomisp: remove hmm/hmm_common.h file

In reply to Nikolay Kulikov

Now this file contains nothing, and we can remove it and all the "#include" directives.

---
 drivers/staging/media/atomisp/include/hmm/hmm.h        |  1 -
 drivers/staging/media/atomisp/include/hmm/hmm_bo.h     |  1 -
 drivers/staging/media/atomisp/include/hmm/hmm_common.h | 16 ----------------
 drivers/staging/media/atomisp/pci/hmm/hmm_bo.c         |  1 -
 4 files changed, 19 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm.h +0 -1
index 6bda02b9ff85..be92a9c9046f 100644
@@ -15,7 +15,6 @@
 #include <linux/slab.h>
 #include <linux/mm.h>
 
-#include "hmm_common.h"
 #include "hmm/hmm_bo.h"
 #include "ia_css_types.h"
 
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +0 -1
index 69cf490bd88c..2a19e3b2c1f9 100644
@@ -16,7 +16,6 @@
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
 #include "mmu/isp_mmu.h"
-#include "hmm/hmm_common.h"
 #include "ia_css_types.h"
 
 #define rbtree_node_to_hmm_bo(root_node)	\
drivers/staging/media/atomisp/include/hmm/hmm_common.h deleted +0 -16
deleted file mode 100644
index 029620347302..000000000000
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Support for Medifield PNW Camera Imaging ISP subsystem.
- *
- * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
- *
- * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
- */
-
-#ifndef	__HMM_BO_COMMON_H__
-#define	__HMM_BO_COMMON_H__
-
-#define	HMM_BO_NAME	"HMM"
-
-
-#endif
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +0 -1
index 7d0ef0f9eec8..c26038be76b6 100644
@@ -30,7 +30,6 @@
 #include <asm/set_memory.h>
 
 #include "atomisp_internal.h"
-#include "hmm/hmm_common.h"
 #include "hmm/hmm_bo.h"
 
 static int __bo_init(struct hmm_bo_device *bdev, struct hmm_buffer_object *bo,
Signature · 1 line
2.55.0
Reviewed-by on the v4 series
#6 lore raw
In reply to Nikolay Kulikov
Quoted 9 lines · Nikolay Kulikov

This series removes unused functions and replaces obscure variable-checking macros with clear conditional statements.

Nikolay Kulikov (5):
staging: media: atomisp: remove unused functions from pci/hmm/
staging: media: atomisp: inline macros for checking the bo/bodev pointer
staging: media: atomisp: inline the check_bo_status_*() macros
staging: media: atomisp: inline the var_equal_return*() macros
staging: media: atomisp: remove hmm/hmm_common.h file

I don't know what the problem is, but in all four versions of this series I have never get patch 5 in my mailbox (yes, I can retrieve it from lore.kernel.org, but the thing is that either corporate spam-filter or something else gates the message to me).

Overall, LGTM, thanks for pursuing this!

for the entire series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko