staging: media: atomisp: cleanup pci/hmm/ code
Subsystems (4)
v2 cover staging: media: atomisp: cleanup pci/hmm/ code
This series removes unused functions and replaces obscure variable-checking macros with clear conditional expressions.
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.
Nikolay Kulikov (4):
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: remove include/hmm/hmm_common.h file
.../staging/media/atomisp/include/hmm/hmm.h | 17 -- .../media/atomisp/include/hmm/hmm_bo.h | 46 ---- .../media/atomisp/include/hmm/hmm_common.h | 60 ----- drivers/staging/media/atomisp/pci/hmm/hmm.c | 41 --- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 240 ++++++++---------- 5 files changed, 109 insertions(+), 295 deletions(-) delete mode 100644 drivers/staging/media/atomisp/include/hmm/hmm_common.h
base-commit: cb08dcd0a896c3ac8073a57296f2377b106c35b4
Signature · 1 line
2.55.0
PATCH v2 1/4 staging: media: atomisp: remove unused functions from pci/hmm/
These functions are declared and defined but are not called anywhere.
--- .../staging/media/atomisp/include/hmm/hmm.h | 16 --- .../media/atomisp/include/hmm/hmm_bo.h | 19 ---- drivers/staging/media/atomisp/pci/hmm/hmm.c | 41 -------- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 97 ------------------- 4 files changed, 173 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm.h +0 -16
@@ -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
@@ -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 -97
112 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v2 1/4] staging: media: atomisp: remove unused functions from pci/hmm/
Quoted 1 line · Nikolay Kulikov
These functions are declared and defined but are not called anywhere.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 2/4 staging: media: atomisp: inline macros for checking the bo/bodev pointer
In reply to Nikolay KulikovThese macros perform a pointer check. Replace it with direct conditional expressions to simplify the code.
--- .../media/atomisp/include/hmm/hmm_bo.h | 14 --- .../media/atomisp/include/hmm/hmm_common.h | 6 - .../staging/media/atomisp/pci/hmm/hmm_bo.c | 104 ++++++++++++++---- 3 files changed, 83 insertions(+), 41 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +0 -14
@@ -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
@@ -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 +83 -21
225 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [PATCH v2 2/4] staging: media: atomisp: inline macros for checking the bo/bodev pointer
Quoted 2 lines · Nikolay Kulikov
These macros perform a pointer check. Replace it with direct conditional expressions to simplify the code.
...
Quoted 6 lines
struct
hmm_buffer_object*hmm_bo_alloc(structhmm_bo_device*bdev,drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +1
-1unsigned int pgnr) {struct hmm_buffer_object *bo, *new_bo; -struct rb_root *root = &bdev->free_rbtree; +struct rb_root *root;
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c struct hmm_buffer_object *hmm_bo_alloc(struct hmm_bo_device *bdev, · line 400
Quoted 10 lines
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +6
-1+ +if (!bdev) { +dev_err (atomisp_dev,"NULL hmm_bo_device.\n" ); +return NULL ; + } -check_bodev_null_return (bdev,NULL ); + root = &bdev->free_rbtree;var_equal_return (hmm_bo_device_inited (bdev),0 ,NULL ,"hmm_bo_device not inited yet.\n" );
While at it, also replace here var_equal_return() with appropriate C code.
...
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c void hmm_bo_device_exit(struct hmm_bo_device *bdev) · line 510
Quoted 9 lines
void
hmm_bo_device_exit(struct hmm_bo_device *bdev)drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +4
-1dev_dbg (atomisp_dev,"%s: entering!\n" , __func__); -check_bodev_null_return_void (bdev); +if (!bdev) { +dev_err (atomisp_dev,"NULL hmm_bo_device.\n" ); +return ; + }
While it's in the original code, usually in kernel we consider releasing or existing functions be NULL-aware. Not sure if we need an error message to be printed here. But I leave it to Sakari to decide.
...
Quoted 3 lines
int hmm_bo_alloc_pages(struct
hmm_buffer_object*bo,
{
int ret =-EINVAL;
Do wee need to keep the above assignment?
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c int hmm_bo_alloc_pages(struct hmm_buffer_object *bo, · line 686
Quoted 4 lines
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +3
-1-check_bo_null_return (bo, -EINVAL ); +if (!bo) { +dev_err (atomisp_dev,"NULL hmm buffer object.\n" ); +return -EINVAL ;
Depending on the above it might be
return ret;
But in such a case the above assignment should be split
int ret;
ret = -EINVAL;
if (!bo) {
dev_err(atomisp_dev, "NULL hmm buffer object.\n");
return ret;Looking now at this, I think that your variant is better, but with it it's better to also check how ret is being used and split assignment.
int ret;
if (!bo) {
dev_err(atomisp_dev, "NULL hmm buffer object.\n");
return -EINVAL;
...
ret = -EINVAL;Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c static void hmm_bo_vm_open(struct vm_area_struct *vma) · line 1008
Quoted 9 lines
static void
hmm_bo_vm_open(struct vm_area_struct *vma)
{drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +4
-1struct hmm_buffer_object *bo = vma->vm_private_data; -check_bo_null_return_void (bo); +if (!bo) { +dev_err (atomisp_dev,"NULL hmm buffer object.\n" ); +return ; + }
In this case it's better to also split an assignment.
struct hmm_buffer_object *bo;
bo = vma->vm_private_data;
if (!bo) {
dev_err(atomisp_dev, "NULL hmm buffer object.\n");
return;
}...
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c static void hmm_bo_vm_open(struct vm_area_struct *vma) · line 1008
Quoted 9 lines
static void
hmm_bo_vm_close(struct vm_area_struct *vma)
{drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +4
-1struct hmm_buffer_object *bo = vma->vm_private_data; -check_bo_null_return_void (bo); +if (!bo) { +dev_err (atomisp_dev,"NULL hmm buffer object.\n" ); +return ; + }
Ditto.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/4] staging: media: atomisp: inline macros for checking the bo/bodev pointer
Quoted 1 line · Andy Shevchenko
On Thu, Jul 23, 2026 at 09:51:19PM +0300, Nikolay Kulikov wrote:
...
Quoted 12 lines
Quoted 12 lines
struct
hmm_buffer_object*hmm_bo_alloc(structhmm_bo_device*bdev,drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +6
-1unsigned int pgnr) {struct hmm_buffer_object *bo, *new_bo; -struct rb_root *root = &bdev->free_rbtree; +struct rb_root *root; + +if (!bdev) { +dev_err (atomisp_dev,"NULL hmm_bo_device.\n" ); +return NULL ; + }
Quoted 6 lines
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c struct hmm_buffer_object *hmm_bo_alloc(struct hmm_bo_device *bdev, · line 400
Quoted 4 lines
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +1
-1-check_bodev_null_return (bdev,NULL ); + root = &bdev->free_rbtree;var_equal_return (hmm_bo_device_inited (bdev),0 ,NULL ,"hmm_bo_device not inited yet.\n" );While at it, also replace here
var_equal_return()with appropriate C code.
Ah, it's done in the last patch!
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 3/4 staging: media: atomisp: inline the check_bo_status_*() macros
In reply to Nikolay KulikovThese macros check a bit in the bo->status field. Replace them with conditional expressions to make the code clearer.
--- .../media/atomisp/include/hmm/hmm_bo.h | 12 -------- .../media/atomisp/include/hmm/hmm_common.h | 18 ----------- .../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
@@ -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
@@ -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
@@ -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
Re: [PATCH v2 3/4] staging: media: atomisp: inline the check_bo_status_*() macros
Quoted 2 lines · Nikolay Kulikov
These macros check a bit in the
bo->statusfield. Replace them with conditional expressions to make the code clearer.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 4/4 staging: media: atomisp: remove include/hmm/hmm_common.h file
In reply to Nikolay KulikovReplace the last used macro with a conditional expression and remove this header file, as it no longer contains any code that is being used.
--- .../staging/media/atomisp/include/hmm/hmm.h | 1 - .../media/atomisp/include/hmm/hmm_bo.h | 1 - .../media/atomisp/include/hmm/hmm_common.h | 36 ------------------- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 9 +++-- 4 files changed, 6 insertions(+), 41 deletions(-) delete mode 100644 drivers/staging/media/atomisp/include/hmm/hmm_common.h
drivers/staging/media/atomisp/include/hmm/hmm.h +0 -1
@@ -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
@@ -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 -36
@@ -1,36 +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" - -/* -* 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 +6 -3
@@ -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,
@@ -389,6 +388,7 @@ struct hmm_buffer_object *hmm_bo_alloc(struct hmm_bo_device *bdev, {struct hmm_buffer_object *bo, *new_bo;struct rb_root *root; +int ret;if (!bdev) {dev_err (atomisp_dev,"NULL hmm_bo_device.\n" );
@@ -396,8 +396,11 @@ 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" ); + ret =hmm_bo_device_inited (bdev); +if (!ret) { +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
Re: [PATCH v2 4/4] staging: media: atomisp: remove include/hmm/hmm_common.h file
Quoted 2 lines · Nikolay Kulikov
Replace the last used macro with a conditional expression and remove this header file, as it no longer contains any code that is being used.
Split this to two patches: replace (in the similar way how previous patches are done) & remove leftovers (file and no more needed includes).
The code wise LGTM, I will give a tag to these patches when they appear in v3 of the series.
...
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c struct hmm_buffer_object *hmm_bo_alloc(struct hmm_bo_device *bdev, · line 400
Quoted 2 lines
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +2
-0+ ret =hmm_bo_device_inited (bdev); +if (!ret) {
In such a case it's better to have
if (!hmm_bo_device_inited(bdev)) {Quoted 3 lines
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +3
-0+dev_err (atomisp_dev,"hmm_bo_device not inited yet.\n" ); +return NULL ; + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/4] staging: media: atomisp: remove include/hmm/hmm_common.h file
Quoted 9 lines · Andy Shevchenko
Quoted 2 lines · Nikolay Kulikov
Replace the last used macro with a conditional expression and remove this header file, as it no longer contains any code that is being used.
Split this to two patches: replace (in the similar way how previous patches are done) & remove leftovers (file and no more needed includes).
The code wise LGTM, I will give a tag to these patches when they appear in v3 of the series.
Hi Andy, thanks for the detailed review of this and the other patchs. I'll fix them and send v3.
Thanks,
Nikolay