Re: [PATCH] media: media-request: Fix crash according to a failed memory allocation

From: Markus Elfring
Date: Sun Jun 21 2020 - 08:45:39 EST


> â, reorder media_request_alloc() such that â

Wording adjustments:
â, reorder statements in the implementation of the function âmedia_request_allocâ so that â


> â the last step thus

â the last step.
Thus media_request_close() â


Would you like to add the tag âFixesâ to the commit message?


â
> +++ b/drivers/media/mc/mc-request.c
> @@ -296,9 +296,18 @@ int media_request_alloc(struct media_device *mdev, int *alloc_fd)
> if (WARN_ON(!mdev->ops->req_alloc ^ !mdev->ops->req_free))
> return -ENOMEM;
>
> + if (mdev->ops->req_alloc)
> + req = mdev->ops->req_alloc(mdev);
> + else
> + req = kzalloc(sizeof(*req), GFP_KERNEL);

How do you think about to use a conditional operator?

+ req = (mdev->ops->req_alloc
? mdev->ops->req_alloc(mdev)
: kzalloc(sizeof(*req), GFP_KERNEL));


Regards,
Markus