From: Hans de Goede <hansg@kernel.org>
To: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>,
andy@kernel.org, mchehab@kernel.org,
sakari.ailus@linux.intel.com, gregkh@linuxfoundation.org
Cc: linux-kernel-mentees@lists.linux.dev,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-staging@lists.linux.dev, skhan@linuxfoundation.com,
dan.carpenter@linaro.org
Subject: Re: [PATCH] staging: media: atomisp: Fix premature setting of HMM_BO_DEVICE_INITED flag
Date: Sun, 6 Jul 2025 18:22:59 +0200 [thread overview]
Message-ID: <fe47fcf0-9d37-451d-8985-9d10a7491eeb@kernel.org> (raw)
In-Reply-To: <20250628052536.43737-1-abdelrahmanfekry375@gmail.com>
Hi,
On 28-Jun-25 7:25 AM, Abdelrahman Fekry wrote:
> The HMM_BO_DEVICE_INITED flag was being set in hmm_bo_device_init()
> before key initialization steps like kmem_cache_create(),
> kmem_cache_alloc(), and __bo_init().
>
> This means that if any of these steps fail, the flag remains set,
> misleading other parts of the driver (e.g. hmm_bo_alloc())
> into thinking the device is initialized. This could lead
> to undefined behavior or invalid memory use.
>
> Additionally, since __bo_init() is called from inside
> hmm_bo_device_init() after the flag was already set, its internal
> check for HMM_BO_DEVICE_INITED is redundant.
>
> - Move the flag assignment to the end after all allocations succeed.
> - Remove redundant check of the flag inside __bo_init()
>
> Signed-off-by: Abdelrahman Fekry <abdelrahmanfekry375@gmail.com>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hansg@kernel.org>
I have adjusted the commit message with a link to the backtrace
you generated through fault-injection and I've merged this in my
media-atomisp branch:
https://git.kernel.org/pub/scm/linux/kernel/git/hansg/linux.git/log/?h=media-atomisp
This patch will be included in my next pull-request
to Mauro (to media subsystem maintainer)
Regards,
Hans
> ---
> drivers/staging/media/atomisp/pci/hmm/hmm_bo.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
> index 224ca8d42721..5d0cd5260d3a 100644
> --- a/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
> +++ b/drivers/staging/media/atomisp/pci/hmm/hmm_bo.c
> @@ -37,8 +37,6 @@ static int __bo_init(struct hmm_bo_device *bdev, struct hmm_buffer_object *bo,
> unsigned int pgnr)
> {
> check_bodev_null_return(bdev, -EINVAL);
> - var_equal_return(hmm_bo_device_inited(bdev), 0, -EINVAL,
> - "hmm_bo_device not inited yet.\n");
> /* prevent zero size buffer object */
> if (pgnr == 0) {
> dev_err(atomisp_dev, "0 size buffer is not allowed.\n");
> @@ -341,7 +339,6 @@ int hmm_bo_device_init(struct hmm_bo_device *bdev,
> spin_lock_init(&bdev->list_lock);
> mutex_init(&bdev->rbtree_mutex);
>
> - bdev->flag = HMM_BO_DEVICE_INITED;
>
> INIT_LIST_HEAD(&bdev->entire_bo_list);
> bdev->allocated_rbtree = RB_ROOT;
> @@ -376,6 +373,8 @@ 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;
> +
> return 0;
> }
>
> --
> 2.25.1
>
>
prev parent reply other threads:[~2025-07-06 16:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-28 5:25 [PATCH] staging: media: atomisp: Fix premature setting of HMM_BO_DEVICE_INITED flag Abdelrahman Fekry
2025-06-28 19:52 ` Andy Shevchenko
2025-06-29 9:51 ` Abdelrahman Fekry
2025-07-01 11:58 ` Abdelrahman Fekry
2025-07-01 12:45 ` Andy Shevchenko
2025-07-01 13:54 ` Hans de Goede
2025-07-01 15:45 ` Abdelrahman Fekry
2025-07-06 18:25 ` Hans de Goede
2025-07-07 10:57 ` Abdelrahman Fekry
2025-07-07 13:26 ` Abdelrahman Fekry
2025-07-07 13:55 ` Hans de Goede
2025-07-01 15:33 ` Abdelrahman Fekry
2025-07-01 18:00 ` Andy Shevchenko
2025-07-06 16:22 ` Hans de Goede [this message]
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=fe47fcf0-9d37-451d-8985-9d10a7491eeb@kernel.org \
--to=hansg@kernel.org \
--cc=abdelrahmanfekry375@gmail.com \
--cc=andy@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=gregkh@linuxfoundation.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.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