All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Hellstrom <thellstrom@vmware.com>
To: David Herrmann <dh.herrmann@gmail.com>
Cc: Dave Airlie <airlied@redhat.com>,
	Thomas Hellstrom <thellstrom@vmware.com>,
	linux-graphics-maintainer@vmware.com,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 2/5] drm: Break out ioctl permission check to a separate function
Date: Thu, 13 Mar 2014 13:28:33 +0100	[thread overview]
Message-ID: <5321A471.2070202@vmware.com> (raw)
In-Reply-To: <CANq1E4T6fq9U_5ttem4qvvq9qSMSy8QY1FNOyP_GzF3-hHzN=A@mail.gmail.com>

On 03/13/2014 01:15 PM, David Herrmann wrote:
> Hi
>
> On Thu, Mar 13, 2014 at 1:11 PM, Thomas Hellstrom <thellstrom@vmware.com> wrote:
>> Hi.
>>
>> Thanks for reviewing. I'll incorporate your suggestions, except this
>> one, and resend.
>>
>>
>> On 03/13/2014 12:19 PM, David Herrmann wrote:
>>> Hi
>>>
>>> On Thu, Mar 13, 2014 at 11:57 AM, Thomas Hellstrom
>>> <thellstrom@vmware.com> wrote:
>> ...
>>
>> -               if (cmd & IOC_IN) {
>> -                       if (copy_from_user(kdata, (void __user *)arg,
>> -                                          usize) != 0) {
>> -                               retcode = -EFAULT;
>> +       retcode = drm_ioctl_permit(ioctl->flags, file_priv);
>> +       if (unlikely(retcode))
>>
>>> That "unlikely" seems redundant given that all error paths in
>>> drm_ioctl_permit() already are "unlikely".
>> Yes, we know that's true, but I don't think compilers in general can
>> combine branch prediction hints in that way,
>> or even have the information necessary to do it.
>> I mean even if each individual test resulting in an error is unlikely,
>> how could the compiler know that
>> all tests combined would result in an error being unlikely?
> The function is static, so the compiler can see that it returns "!=0"
> only if one of the "unlikely" branches was hit. So I think it's safe
> to assume the whole thing returns "!=0" only in unlikely conditions.
>

But a compiler can't (or shouldn't) make that assumption. Just as an
(adapted) example, imagine that
each test had a 20% probability of returning an error. The probability
of the function returning an error would
then be 68%..

> I'm no big fan of excessive likely/unlikely annotations, but I'm fine
> if you want to keep it.

Fair enough.

Thanks,
Thomas


>
> Thanks
> David
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2014-03-13 12:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-13 10:57 (unknown), Thomas Hellstrom
2014-03-13 10:57 ` [PATCH 1/5] drm: Have the crtc code only reference master from legacy nodes Thomas Hellstrom
2014-03-13 11:12   ` David Herrmann
2014-03-13 10:57 ` [PATCH 2/5] drm: Break out ioctl permission check to a separate function Thomas Hellstrom
2014-03-13 11:19   ` David Herrmann
2014-03-13 12:11     ` Thomas Hellstrom
2014-03-13 12:15       ` David Herrmann
2014-03-13 12:28         ` Thomas Hellstrom [this message]
2014-03-13 18:47           ` Daniel Vetter
2014-03-13 10:57 ` [PATCH 3/5] drm: Make control nodes master-less v2 Thomas Hellstrom
2014-03-13 11:23   ` David Herrmann
2014-03-13 10:57 ` [PATCH 4/5] drm: Improve on minor type helpers Thomas Hellstrom
2014-03-13 10:57 ` [PATCH 5/5] drm: Remove the minor master list Thomas Hellstrom
2014-03-13 11:01 ` [PATCH 0/5] Control node master fixes WAS: Thomas Hellstrom

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=5321A471.2070202@vmware.com \
    --to=thellstrom@vmware.com \
    --cc=airlied@redhat.com \
    --cc=dh.herrmann@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-graphics-maintainer@vmware.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.