mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jinjie Ruan <ruanjinjie@huawei.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	<frank.binns@imgtec.com>, <matt.coster@imgtec.com>,
	<maarten.lankhorst@linux.intel.com>, <mripard@kernel.org>,
	<tzimmermann@suse.de>, <airlied@gmail.com>, <daniel@ffwll.ch>,
	<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH -next] drm/imagination: Use memdup_user() helper
Date: Mon, 2 Sep 2024 10:17:20 +0800	[thread overview]
Message-ID: <b493404f-9f7e-6f90-893e-84ff2bcb0170@huawei.com> (raw)
In-Reply-To: <74dfe952-2055-4152-90c6-ac9cc42fcad9@wanadoo.fr>



On 2024/8/31 18:48, Christophe JAILLET wrote:
> Le 31/08/2024 à 12:30, Jinjie Ruan a écrit :
>> Switching to memdup_user(), which combines kmalloc() and
>> copy_from_user(),
>> and it can simplfy code.
>>
>> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
>> ---
>>   drivers/gpu/drm/imagination/pvr_context.c | 22 +++++++---------------
>>   1 file changed, 7 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/imagination/pvr_context.c
>> b/drivers/gpu/drm/imagination/pvr_context.c
>> index eded5e955cc0..e75fd50a4d9f 100644
>> --- a/drivers/gpu/drm/imagination/pvr_context.c
>> +++ b/drivers/gpu/drm/imagination/pvr_context.c
>> @@ -69,27 +69,19 @@ process_static_context_state(struct pvr_device
>> *pvr_dev, const struct pvr_stream
>>       void *stream;
>>       int err;
>>   -    stream = kzalloc(stream_size, GFP_KERNEL);
>> -    if (!stream)
>> -        return -ENOMEM;
>> -
>> -    if (copy_from_user(stream, u64_to_user_ptr(stream_user_ptr),
>> stream_size)) {
>> -        err = -EFAULT;
>> -        goto err_free;
>> -    }
>> +    stream = memdup_user(u64_to_user_ptr(stream_user_ptr), stream_size);
>> +    if (IS_ERR(stream))
>> +        return PTR_ERR(stream);
>>         err = pvr_stream_process(pvr_dev, cmd_defs, stream,
>> stream_size, dest);
>> -    if (err)
>> -        goto err_free;
>> +    if (err) {
>> +        kfree(stream);
>> +        return err;
>> +    }
>>         kfree(stream);
>>         return 0;
>> -
>> -err_free:
>> -    kfree(stream);
>> -
>> -    return err;
>>   }
> 
> It could also be:
>      err = pvr_stream_process(...);
> 
>      kfree(stream);
> 
>      return err;
> 
> as you did for drivers/gpu/drm/imagination/pvr_job.c.

You are right! that will be more clean.

> 
> CJ
> 
>>     static int init_render_fw_objs(struct pvr_context *ctx,
> 
> 

      reply	other threads:[~2024-09-02  2:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-31 10:30 Jinjie Ruan
2024-08-31 10:48 ` Christophe JAILLET
2024-09-02  2:17   ` Jinjie Ruan [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=b493404f-9f7e-6f90-893e-84ff2bcb0170@huawei.com \
    --to=ruanjinjie@huawei.com \
    --cc=airlied@gmail.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=frank.binns@imgtec.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matt.coster@imgtec.com \
    --cc=mripard@kernel.org \
    --cc=tzimmermann@suse.de \
    /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

all inboxes | Powered by JetHome®