From: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
To: hansg@kernel.org, mchehab@kernel.org,
sakari.ailus@linux.intel.com, andy@kernel.org,
gregkh@linuxfoundation.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-staging@lists.linux.dev,
linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org,
dan.carpenter@linaro.org,
Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
Subject: [PATCH 2/3] staging: media: atomisp: unify HMM initialization tracking
Date: Sat, 12 Jul 2025 22:13:24 +0300 [thread overview]
Message-ID: <20250712191325.132666-3-abdelrahmanfekry375@gmail.com> (raw)
In-Reply-To: <20250712191325.132666-1-abdelrahmanfekry375@gmail.com>
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.
- Replaces the device-specific `flag` with a boolean `initialized` field
- Removes the global `hmm_initialized` variable
- Eliminates the hmm_bo_device_inited() helper function
- Removes the redundant hmm_init() call from __hmm_alloc()
Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
---
.../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(-)
diff --git a/drivers/staging/media/atomisp/include/hmm/hmm_bo.h b/drivers/staging/media/atomisp/include/hmm/hmm_bo.h
index e09ac29ac43d..ac556c1d71bb 100644
--- a/drivers/staging/media/atomisp/include/hmm/hmm_bo.h
+++ b/drivers/staging/media/atomisp/include/hmm/hmm_bo.h
@@ -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.
*/
diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm.c b/drivers/staging/media/atomisp/pci/hmm/hmm.c
index 97c7ce970aef..8d64e5fd812c 100644
--- a/drivers/staging/media/atomisp/pci/hmm/hmm.c
+++ b/drivers/staging/media/atomisp/pci/hmm/hmm.c
@@ -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);
diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
index 5d0cd5260d3a..aabb2a126caa 100644
--- a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
+++ b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
@@ -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)
--
2.25.1
next prev parent reply other threads:[~2025-07-12 19:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-12 19:13 [PATCH 0/3] staging: media: atomisp: More Cleanup on driver AtomIsp Abdelrahman Fekry
2025-07-12 19:13 ` [PATCH 1/3] staging: media: atomisp: return early on hmm_bo_device_init() failure Abdelrahman Fekry
2025-07-12 19:13 ` Abdelrahman Fekry [this message]
2025-07-12 19:13 ` [PATCH 3/3] staging: media: atomisp: move hmm_get_mmu_base_addr() Abdelrahman Fekry
2025-07-16 18:21 ` [PATCH 0/3] staging: media: atomisp: More Cleanup on driver AtomIsp Dan Carpenter
2025-07-17 1:35 ` Abdelrahman Fekry
2025-07-31 3:24 ` Abdelrahman Fekry
2025-07-31 4:35 ` Greg KH
2025-07-31 5:59 ` Abdelrahman Fekry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250712191325.132666-3-abdelrahmanfekry375@gmail.com \
--to=abdelrahmanfekry375@gmail.com \
--cc=andy@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.