staging: media: atomisp: return early on hmm_bo_device_init() failure
Subsystems (4)
PATCH v2 1/2 staging: media: atomisp: return early on hmm_bo_device_init() failure
hmm_init() would continue execution even if hmm_bo_device_init() failed, potentially leading to bad behaviour when calling hmm_alloc().
- returns the error immediately if hmm_bo_device_init() fails.
Tested by:
- Building the Driver.
- Applying to media-committers [1] tree.
---
v2:
- put brackets around block code.
v1: https://lore.kernel.org/all/[email protected]/
drivers/staging/media/atomisp/pci/hmm/hmm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/media/atomisp/pci/hmm/hmm.c +4 -2
@@ -34,8 +34,10 @@ int hmm_init(void) ret =hmm_bo_device_init (&bo_device, &sh_mmu_mrfld,ISP_VM_START ,ISP_VM_SIZE ); -if (ret) +if (ret) {dev_err (atomisp_dev,"hmm_bo_device_init failed.\n" ); +return ret; + } hmm_initialized = true;
@@ -48,7 +50,7 @@ int hmm_init(void)*/ dummy_ptr =hmm_alloc (1 ); -return ret; +return 0 ; }void hmm_cleanup (void )
Signature · 1 line
2.25.1
PATCH v2 2/2 staging: media: atomisp: unify HMM initialization tracking
The HMM subsystem previously used two separate mechanisms to track initialization state:
1. A global boolean hmm_initialized in hmm.c
2. A device-specific flag in struct hmm_bo_device with magic values
This dual approach was redundant and error-prone. Additionally, a redundant hmm_init() call existed in the allocation path.
This patch:
- Replaces the device-specific flag with a boolean initialized field
- Removes the global hmm_initialized variable
- Eliminates the hmm_bo_device_inited() helper function since we can now simply check the boolean
- Removes the redundant hmm_init() call from __hmm_alloc() since its always called after hmm_init()
Tested by:
- Building the Driver.
- Applying to media-committers [1] tree.
---
v2:
- replaces the init state enum used in v1 with boolean
- moves setting the flag uninited to hmm_bo_device_exit()
v1: https://lore.kernel.org/all/[email protected]/
.../staging/media/atomisp/include/hmm/hmm_bo.h | 11 +++-------- drivers/staging/media/atomisp/pci/hmm/hmm.c | 11 ----------- drivers/staging/media/atomisp/pci/hmm/hmm_bo.c | 17 ++++++----------- 3 files changed, 9 insertions(+), 30 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +3 -8
@@ -58,8 +58,6 @@#define ISP_VM_SIZE (0x7FFFFFFF)/* 2G address space */ #define ISP_PTR_NULL NULL -#define HMM_BO_DEVICE_INITED 0x1 -enum hmm_bo_type {HMM_BO_PRIVATE ,HMM_BO_VMALLOC ,
@@ -86,7 +84,9 @@ struct hmm_bo_device {/* list lock is used to protect the entire_bo_list */ spinlock_t list_lock; -int flag; + +/* boolean to indicate whether the bo device is inited or not*/ +bool initialized;/* linked list for entire buffer object */ struct list_head entire_bo_list;
@@ -142,11 +142,6 @@ int hmm_bo_device_init(struct hmm_bo_device *bdev,*/ void hmm_bo_device_exit (struct hmm_bo_device *bdev); -/* -* whether the bo device is inited or not. -*/ -int hmm_bo_device_inited (struct hmm_bo_device *bdev); -/* * increase buffer object reference. */
drivers/staging/media/atomisp/pci/hmm/hmm.c +0 -11
@@ -26,7 +26,6 @@struct hmm_bo_device bo_device;static ia_css_ptr dummy_ptr = mmgr_EXCEPTION; -static bool hmm_initialized;int hmm_init (void ) {
@@ -39,8 +38,6 @@ int hmm_init(void)return ret; } - hmm_initialized = true; -/* * As hmm use NULL to indicate invalid ISP virtual address, * and ISP_VM_START is defined to 0 too, so we allocate
@@ -63,7 +60,6 @@ void hmm_cleanup(void) dummy_ptr =0 ;hmm_bo_device_exit (&bo_device); - hmm_initialized = false; } static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type,
@@ -73,13 +69,6 @@ static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type,struct hmm_buffer_object *bo;int ret; -/* -* Check if we are initialized. In the ideal world we wouldn't need -* this but we can tackle it once the driver is a lot cleaner -*/ - -if (!hmm_initialized) -hmm_init ();/* Get page number from size */ pgnr =size_to_pgnr_ceil (bytes);
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +6 -11
@@ -373,7 +373,7 @@ int hmm_bo_device_init(struct hmm_bo_device *bdev,__bo_insert_to_free_rbtree (&bdev->free_rbtree, bo); - bdev->flag =HMM_BO_DEVICE_INITED ; + bdev->initialized = true;return 0 ; }
@@ -385,9 +385,10 @@ struct hmm_buffer_object *hmm_bo_alloc(struct hmm_bo_device *bdev,struct rb_root *root = &bdev->free_rbtree;check_bodev_null_return (bdev,NULL ); -var_equal_return (hmm_bo_device_inited (bdev),0 ,NULL , -"hmm_bo_device not inited yet.\n" ); - +if (!bdev->initialized) { +dev_err (atomisp_dev,"hmm_bo_device is not initialized!\n" ); +return NULL ; + }if (pgnr ==0 ) {dev_err (atomisp_dev,"0 size buffer is not allowed.\n" );return NULL ;
@@ -522,13 +523,7 @@ void hmm_bo_device_exit(struct hmm_bo_device *bdev)kmem_cache_destroy (bdev->bo_cache);isp_mmu_exit (&bdev->mmu); -} - -int hmm_bo_device_inited (struct hmm_bo_device *bdev) -{ -check_bodev_null_return (bdev, -EINVAL ); - -return bdev->flag ==HMM_BO_DEVICE_INITED ; + bdev->initialized = false; }int hmm_bo_allocated (struct hmm_buffer_object *bo)
Signature · 1 line
2.25.1