From: Tomeu Vizoso <tomeu.vizoso@collabora.com>
To: Emil Velikov <emil.l.velikov@gmail.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"Linux-Kernel@Vger. Kernel. Org" <linux-kernel@vger.kernel.org>,
ML dri-devel <dri-devel@lists.freedesktop.org>,
Daniel Vetter <daniel.vetter@intel.com>,
Emil Velikov <emil.velikov@collabora.com>
Subject: Re: [PATCH v6 2/4] drm: Add API for capturing frame CRCs
Date: Thu, 8 Sep 2016 16:49:32 +0200 [thread overview]
Message-ID: <CAAObsKDHj6yuwcRSio8a7brAuzYhxkp5VHVHkwze99YGzmEscw@mail.gmail.com> (raw)
In-Reply-To: <CACvgo51fga9E39cnjdxrVEM8mEL_84se9mdroGeqHtiC_T0=OQ@mail.gmail.com>
On 8 September 2016 at 15:24, Emil Velikov <emil.l.velikov@gmail.com> wrote:
> Hi Tomeu,
>
> A couple of small nitpicks and a rather nasty looking bug, related to
> your earlier question.
>
> On 7 September 2016 at 11:27, Tomeu Vizoso <tomeu.vizoso@collabora.com> wrote:
>
>> +static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
>> + size_t len, loff_t *offp)
>> +{
>
>> + if (source[len] == '\n')
>> + source[len] = '\0';
>> +
> Considering the bug below, I'm considering if there's a case were we
> don't want to explicitly set the terminating byte ?
>
>
>> +/*
>> + * 1 frame field of 10 chars plus a number of CRC fields of 10 chars each, space
>> + * separated, with a newline at the end and null-terminated.
>> + */
> NULL-terminated what the things that was missing, explaining the
> maths. Yet note the code sort of contradicts it.
>
> TL;DR: above we conditionally NULL terminate the data, yet (below) we
> feed garbage (always) instead of \0 byte.
>
>> +#define LINE_LEN(values_cnt) (10 + 11 * values_cnt + 1 + 1)
>> +#define MAX_LINE_LEN (LINE_LEN(DRM_MAX_CRC_NR))
>> +
>> +static ssize_t crtc_crc_read(struct file *filep, char __user *user_buf,
>> + size_t count, loff_t *pos)
>> +{
>> + struct drm_crtc *crtc = filep->f_inode->i_private;
>> + struct drm_crtc_crc *crc = &crtc->crc;
>> + struct drm_crtc_crc_entry *entry;
>> + char buf[MAX_LINE_LEN];
> Here buf is filled with garbage...
>
>
>> + if (entry->has_frame_counter)
>> + sprintf(buf, "0x%08x", entry->frame);
>> + else
>> + sprintf(buf, "XXXXXXXXXX");
>> +
>> + for (i = 0; i < crc->values_cnt; i++)
>> + sprintf(buf + 10 + i * 11, " 0x%08x", entry->crcs[i]);
>> + sprintf(buf + 10 + crc->values_cnt * 11, "\n");
>> +
> ... and now all the data is in, incl. the \n byte.
>
>> + if (copy_to_user(user_buf, buf, LINE_LEN(crc->values_cnt)))
> And here we copy the whole thing incl. the 'should be \0 but is
> actually garbage' byte.
As discussed offline, sprintf does terminate the string for us, so I
think this is fine.
> This doesn't look good :-\
>
>> --- a/drivers/gpu/drm/drm_drv.c
>> +++ b/drivers/gpu/drm/drm_drv.c
>
>> @@ -221,6 +222,14 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type)
>> return ret;
>> }
>>
>> + if (type == DRM_MINOR_PRIMARY) {
>> + drm_for_each_crtc(crtc, dev) {
>> + ret = drm_debugfs_crtc_add(crtc);
>> + if (ret)
>> + DRM_ERROR("DRM: Failed to initialize CRC debugfs.\n");
>> + }
>> + }
>> +
> Minor: We're missing teardown in the error path.
Isn't drm_debugfs_cleanup taking care of it?
>
>> --- /dev/null
>> +++ b/include/drm/drm_debugfs_crc.h
>
>> +static inline int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
> Minor: The function is internal only and used only when
> defined(CONFIG_DEBUG_FS). Thus it should stay in
> drivers/gpu/drm/foo.h.
>
> Rule of thumb: include/drm defines the API used by the drivers, while
> drivers/gpu/drm/foo_internal.h the internal API between the core DRM
> modules.
Good one.
Thanks!
Tomeu
next prev parent reply other threads:[~2016-09-08 14:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-07 10:27 [PATCH v6 0/4] New debugfs API for capturing CRC of frames Tomeu Vizoso
2016-09-07 10:27 ` [PATCH v6 1/4] drm/i915/debugfs: Move out pipe CRC code Tomeu Vizoso
2016-09-07 10:27 ` [PATCH v6 2/4] drm: Add API for capturing frame CRCs Tomeu Vizoso
2016-09-08 13:24 ` Emil Velikov
2016-09-08 14:49 ` Tomeu Vizoso [this message]
2016-09-08 15:08 ` Emil Velikov
2016-09-07 10:27 ` [PATCH v6 3/4] drm/i915: Use new CRC debugfs API Tomeu Vizoso
2016-09-08 13:35 ` [Intel-gfx] " Emil Velikov
2016-09-08 14:47 ` Tomeu Vizoso
2016-09-07 10:27 ` [PATCH v6 4/4] drm/i915: Put "cooked" vlank counters in frame CRC lines Tomeu Vizoso
2016-09-08 13:38 ` [Intel-gfx] [PATCH v6 0/4] New debugfs API for capturing CRC of frames Emil Velikov
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=CAAObsKDHj6yuwcRSio8a7brAuzYhxkp5VHVHkwze99YGzmEscw@mail.gmail.com \
--to=tomeu.vizoso@collabora.com \
--cc=corbet@lwn.net \
--cc=daniel.vetter@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
--cc=emil.velikov@collabora.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).