From: Nikolay Kulikov <nikolayof23@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Hans de Goede <hansg@kernel.org>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Andy Shevchenko <andy@kernel.org>
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org,
Nikolay Kulikov <nikolayof23@gmail.com>
Subject: [PATCH v2 2/4] staging: media: atomisp: inline macros for checking the bo/bodev pointer
Date: Thu, 23 Jul 2026 21:51:19 +0300 [thread overview]
Message-ID: <20260723185217.317981-3-nikolayof23@gmail.com> (raw)
In-Reply-To: <20260723185217.317981-1-nikolayof23@gmail.com>
These macros perform a pointer check. Replace it with direct conditional
expressions to simplify the code.
Signed-off-by: Nikolay Kulikov <nikolayof23@gmail.com>
---
.../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(-)
diff --git a/drivers/staging/media/atomisp/include/hmm/hmm_bo.h b/drivers/staging/media/atomisp/include/hmm/hmm_bo.h
index ba3c582a0f89..e974ab5ca2fc 100644
--- a/drivers/staging/media/atomisp/include/hmm/hmm_bo.h
+++ b/drivers/staging/media/atomisp/include/hmm/hmm_bo.h
@@ -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
diff --git a/drivers/staging/media/atomisp/include/hmm/hmm_common.h b/drivers/staging/media/atomisp/include/hmm/hmm_common.h
index b251e96cc19d..f215130e5e17 100644
--- a/drivers/staging/media/atomisp/include/hmm/hmm_common.h
+++ b/drivers/staging/media/atomisp/include/hmm/hmm_common.h
@@ -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
diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
index 837077f1d229..b9949cc080e5 100644
--- a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
+++ b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
@@ -36,7 +36,10 @@
static int __bo_init(struct hmm_bo_device *bdev, struct hmm_buffer_object *bo,
unsigned int pgnr)
{
- check_bodev_null_return(bdev, -EINVAL);
+ if (!bdev) {
+ dev_err(atomisp_dev, "NULL hmm_bo_device.\n");
+ return -EINVAL;
+ }
/* prevent zero size buffer object */
if (pgnr == 0) {
dev_err(atomisp_dev, "0 size buffer is not allowed.\n");
@@ -324,7 +327,10 @@ int hmm_bo_device_init(struct hmm_bo_device *bdev,
unsigned long flags;
int ret;
- check_bodev_null_return(bdev, -EINVAL);
+ if (!bdev) {
+ dev_err(atomisp_dev, "NULL hmm_bo_device.\n");
+ return -EINVAL;
+ }
ret = isp_mmu_init(&bdev->mmu, mmu_driver);
if (ret) {
@@ -382,9 +388,14 @@ struct hmm_buffer_object *hmm_bo_alloc(struct hmm_bo_device *bdev,
unsigned 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;
+ }
- 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");
@@ -493,7 +504,10 @@ void hmm_bo_device_exit(struct hmm_bo_device *bdev)
dev_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;
+ }
/*
* release all allocated bos even they a in use
@@ -526,14 +540,20 @@ void hmm_bo_device_exit(struct hmm_bo_device *bdev)
int hmm_bo_device_inited(struct hmm_bo_device *bdev)
{
- check_bodev_null_return(bdev, -EINVAL);
+ if (!bdev) {
+ dev_err(atomisp_dev, "NULL hmm_bo_device.\n");
+ return -EINVAL;
+ }
return bdev->flag == HMM_BO_DEVICE_INITED;
}
int hmm_bo_allocated(struct hmm_buffer_object *bo)
{
- check_bo_null_return(bo, 0);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return 0;
+ }
return bo->status & HMM_BO_ALLOCED;
}
@@ -543,7 +563,10 @@ struct hmm_buffer_object *hmm_bo_device_search_start(
{
struct hmm_buffer_object *bo;
- check_bodev_null_return(bdev, NULL);
+ if (!bdev) {
+ dev_err(atomisp_dev, "NULL hmm_bo_device.\n");
+ return NULL;
+ }
mutex_lock(&bdev->rbtree_mutex);
bo = __bo_search_by_addr(&bdev->allocated_rbtree, vaddr);
@@ -563,7 +586,10 @@ struct hmm_buffer_object *hmm_bo_device_search_in_range(
{
struct hmm_buffer_object *bo;
- check_bodev_null_return(bdev, NULL);
+ if (!bdev) {
+ dev_err(atomisp_dev, "NULL hmm_bo_device.\n");
+ return NULL;
+ }
mutex_lock(&bdev->rbtree_mutex);
bo = __bo_search_by_addr_in_range(&bdev->allocated_rbtree, vaddr);
@@ -655,7 +681,10 @@ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo,
{
int ret = -EINVAL;
- check_bo_null_return(bo, -EINVAL);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return -EINVAL;
+ }
mutex_lock(&bo->mutex);
check_bo_status_no_goto(bo, HMM_BO_PAGE_ALLOCED, status_err);
@@ -702,7 +731,10 @@ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo,
*/
void hmm_bo_free_pages(struct hmm_buffer_object *bo)
{
- check_bo_null_return_void(bo);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return;
+ }
mutex_lock(&bo->mutex);
@@ -731,7 +763,10 @@ void hmm_bo_free_pages(struct hmm_buffer_object *bo)
int hmm_bo_page_allocated(struct hmm_buffer_object *bo)
{
- check_bo_null_return(bo, 0);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return 0;
+ }
return bo->status & HMM_BO_PAGE_ALLOCED;
}
@@ -746,7 +781,10 @@ int hmm_bo_bind(struct hmm_buffer_object *bo)
struct hmm_bo_device *bdev;
unsigned int i;
- check_bo_null_return(bo, -EINVAL);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return -EINVAL;
+ }
mutex_lock(&bo->mutex);
@@ -823,7 +861,10 @@ void hmm_bo_unbind(struct hmm_buffer_object *bo)
struct hmm_bo_device *bdev;
unsigned int i;
- check_bo_null_return_void(bo);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return;
+ }
mutex_lock(&bo->mutex);
@@ -862,7 +903,10 @@ void hmm_bo_unbind(struct hmm_buffer_object *bo)
void *hmm_bo_vmap(struct hmm_buffer_object *bo, bool cached)
{
- check_bo_null_return(bo, NULL);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return NULL;
+ }
mutex_lock(&bo->mutex);
if (((bo->status & HMM_BO_VMAPED) && !cached) ||
@@ -893,7 +937,10 @@ void *hmm_bo_vmap(struct hmm_buffer_object *bo, bool cached)
void hmm_bo_flush_vmap(struct hmm_buffer_object *bo)
{
- check_bo_null_return_void(bo);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return;
+ }
mutex_lock(&bo->mutex);
if (!(bo->status & HMM_BO_VMAPED_CACHED) || !bo->vmap_addr) {
@@ -907,7 +954,10 @@ void hmm_bo_flush_vmap(struct hmm_buffer_object *bo)
void hmm_bo_vunmap(struct hmm_buffer_object *bo)
{
- check_bo_null_return_void(bo);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return;
+ }
mutex_lock(&bo->mutex);
if (bo->status & HMM_BO_VMAPED || bo->status & HMM_BO_VMAPED_CACHED) {
@@ -922,7 +972,10 @@ void hmm_bo_vunmap(struct hmm_buffer_object *bo)
void hmm_bo_ref(struct hmm_buffer_object *bo)
{
- check_bo_null_return_void(bo);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return;
+ }
kref_get(&bo->kref);
}
@@ -937,7 +990,10 @@ static void kref_hmm_bo_release(struct kref *kref)
void hmm_bo_unref(struct hmm_buffer_object *bo)
{
- check_bo_null_return_void(bo);
+ if (!bo) {
+ dev_err(atomisp_dev, "NULL hmm buffer object.\n");
+ return;
+ }
kref_put(&bo->kref, kref_hmm_bo_release);
}
@@ -946,7 +1002,10 @@ static void hmm_bo_vm_open(struct vm_area_struct *vma)
{
struct 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;
+ }
hmm_bo_ref(bo);
@@ -963,7 +1022,10 @@ static void hmm_bo_vm_close(struct vm_area_struct *vma)
{
struct 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;
+ }
hmm_bo_unref(bo);
--
2.55.0
next prev parent reply other threads:[~2026-07-23 18:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 18:51 [PATCH v2 0/4] staging: media: atomisp: cleanup pci/hmm/ code Nikolay Kulikov
2026-07-23 18:51 ` [PATCH v2 1/4] staging: media: atomisp: remove unused functions from pci/hmm/ Nikolay Kulikov
2026-08-12 7:49 ` Andy Shevchenko
2026-07-23 18:51 ` Nikolay Kulikov [this message]
2026-08-12 7:49 ` [PATCH v2 2/4] staging: media: atomisp: inline macros for checking the bo/bodev pointer Andy Shevchenko
2026-08-12 7:52 ` Andy Shevchenko
2026-07-23 18:51 ` [PATCH v2 3/4] staging: media: atomisp: inline the check_bo_status_*() macros Nikolay Kulikov
2026-08-12 7:51 ` Andy Shevchenko
2026-07-23 18:51 ` [PATCH v2 4/4] staging: media: atomisp: remove include/hmm/hmm_common.h file Nikolay Kulikov
2026-08-12 7:56 ` Andy Shevchenko
2026-08-12 17:22 ` Nikolay Kulikov
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=20260723185217.317981-3-nikolayof23@gmail.com \
--to=nikolayof23@gmail.com \
--cc=andy@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hansg@kernel.org \
--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 \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox