[PATCH] drm: Fix a infinite loop condition when order becomes 0

Paul Menzel pmenzel at molgen.mpg.de
Tue Mar 15 09:05:33 UTC 2022


Dear Arunpravin,


Am 15.03.22 um 10:01 schrieb Arunpravin:

> On 15/03/22 1:49 pm, Paul Menzel wrote:

>> Am 14.03.22 um 20:40 schrieb Arunpravin:
>>> handle a situation in the condition order-- == min_order,
>>> when order = 0, leading to order = -1, it now won't exit
>>> the loop. To avoid this problem, added a order check in
>>> the same condition, (i.e) when order is 0, we return
>>> -ENOSPC
>>>
>>> Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam at amd.com>
>>
>> Please use your full name.
> okay

You might also configure that in your email program.

>>> ---
>>>    drivers/gpu/drm/drm_buddy.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
>>> index 72f52f293249..5ab66aaf2bbd 100644
>>> --- a/drivers/gpu/drm/drm_buddy.c
>>> +++ b/drivers/gpu/drm/drm_buddy.c
>>
>> In what tree is that file?
>>
> drm-tip - https://cgit.freedesktop.org/drm-tip/tree/
> drm-misc-next - https://cgit.freedesktop.org/drm/drm-misc/tree/
> 
>>> @@ -685,7 +685,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm,
>>>    			if (!IS_ERR(block))
>>>    				break;
>>>    
>>> -			if (order-- == min_order) {
>>> +			if (!order || order-- == min_order) {
>>>    				err = -ENOSPC;
>>>    				goto err_free;
>>>    			}

Thank you for the hint. So the whole function is:

	do {
		order = min(order, (unsigned int)fls(pages) - 1);
		BUG_ON(order > mm->max_order);
		BUG_ON(order < min_order);

		do {
			if (flags & DRM_BUDDY_RANGE_ALLOCATION)
				/* Allocate traversing within the range */
				block = alloc_range_bias(mm, start, end, order);
			else
				/* Allocate from freelist */
				block = alloc_from_freelist(mm, order, flags);

			if (!IS_ERR(block))
				break;

			if (order-- == min_order) {
				err = -ENOSPC;
				goto err_free;
			}
		} while (1);

		mark_allocated(block);
		mm->avail -= drm_buddy_block_size(mm, block);
		kmemleak_update_trace(block);
		list_add_tail(&block->link, &allocated);

		pages -= BIT(order);

		if (!pages)
			break;
	} while (1);

Was the BUG_ON triggered for your case?

	BUG_ON(order < min_order);

Please give more details.


Kind regards,

Paul


More information about the dri-devel mailing list