public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Jani Nikula <jani.nikula@linux.intel.com>
Cc: "Eric Engestrom" <eric.engestrom@imgtec.com>,
	"Tom St Denis" <tom.stdenis@amd.com>,
	intel-gfx@lists.freedesktop.org,
	"Eric Engestrom" <eric@engestrom.ch>,
	"Michel Dänzer" <michel.daenzer@amd.com>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	"Xinliang Liu" <z.liuxinliang@hisilicon.com>,
	"David Zhang" <david1.zhang@amd.com>,
	"Wei Yongjun" <yongjun_wei@trendmicro.com.cn>,
	"Vitaly Prosyak" <vitaly.prosyak@amd.com>,
	"Daniel Vetter" <daniel.vetter@intel.com>,
	"Junwei Zhang" <Jerry.Zhang@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Flora Cui" <Flora.Cui@amd.com>,
	"Gustavo Padovan" <gustavo.padovan@collabora.co.uk>,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH] drm: make drm_get_format_name thread-safe
Date: Mon, 15 Aug 2016 15:52:07 +0200	[thread overview]
Message-ID: <20160815135207.GG6232@phenom.ffwll.local> (raw)
In-Reply-To: <87y43ytbsd.fsf@intel.com>

On Mon, Aug 15, 2016 at 04:13:54PM +0300, Jani Nikula wrote:
> On Mon, 15 Aug 2016, Eric Engestrom <eric.engestrom@imgtec.com> wrote:
> > On Mon, Aug 15, 2016 at 12:54:01PM +0300, Jani Nikula wrote:
> >> On Mon, 15 Aug 2016, Eric Engestrom <eric@engestrom.ch> wrote:
> >> > Signed-off-by: Eric Engestrom <eric@engestrom.ch>
> >> > ---
> >> >
> >> > I moved the main bits to be the first diffs, shouldn't affect anything
> >> > when applying the patch, but I wanted to ask:
> >> > I don't like the hard-coded `32` the appears in both kmalloc() and
> >> > snprintf(), what do you think? If you don't like it either, what would
> >> > you suggest? Should I #define it?
> >> >
> >> > Second question is about the patch mail itself: should I send this kind
> >> > of patch separated by module, with a note requesting them to be squashed
> >> > when applying? It has to land as a single patch, but for review it might
> >> > be easier if people only see the bits they each care about, as well as
> >> > to collect ack's/r-b's.
> >> >
> >> > Cheers,
> >> >   Eric
> >> >
> >> > ---
> >> >  drivers/gpu/drm/amd/amdgpu/dce_v10_0.c          |  6 ++--
> >> >  drivers/gpu/drm/amd/amdgpu/dce_v11_0.c          |  6 ++--
> >> >  drivers/gpu/drm/amd/amdgpu/dce_v8_0.c           |  6 ++--
> >> >  drivers/gpu/drm/drm_atomic.c                    |  5 ++--
> >> >  drivers/gpu/drm/drm_crtc.c                      | 21 ++++++++-----
> >> >  drivers/gpu/drm/drm_fourcc.c                    | 17 ++++++-----
> >> >  drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c |  6 ++--
> >> >  drivers/gpu/drm/i915/i915_debugfs.c             | 11 ++++++-
> >> >  drivers/gpu/drm/i915/intel_atomic_plane.c       |  6 ++--
> >> >  drivers/gpu/drm/i915/intel_display.c            | 39 ++++++++++++++++---------
> >> >  drivers/gpu/drm/radeon/atombios_crtc.c          | 12 +++++---
> >> >  include/drm/drm_fourcc.h                        |  2 +-
> >> >  12 files changed, 89 insertions(+), 48 deletions(-)
> >> >
> >> > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> >> > index 0645c85..38216a1 100644
> >> > --- a/drivers/gpu/drm/drm_fourcc.c
> >> > +++ b/drivers/gpu/drm/drm_fourcc.c
> >> > @@ -39,16 +39,14 @@ static char printable_char(int c)
> >> >   * drm_get_format_name - return a string for drm fourcc format
> >> >   * @format: format to compute name of
> >> >   *
> >> > - * Note that the buffer used by this function is globally shared and owned by
> >> > - * the function itself.
> >> > - *
> >> > - * FIXME: This isn't really multithreading safe.
> >> > + * Note that the buffer returned by this function is owned by the caller
> >> > + * and will need to be freed.
> >> >   */
> >> >  const char *drm_get_format_name(uint32_t format)
> >> 
> >> I find it surprising that a function that allocates a buffer returns a
> >> const pointer. Some userspace libraries have conventions about the
> >> ownership based on constness.
> >> 
> >> (I also find it suprising that kfree() takes a const pointer; arguably
> >> that call changes the memory.)
> >> 
> >> Is there precedent for this?
> >> 
> >> BR,
> >> Jani.
> >
> > It's not a const pointer, it's a normal pointer to a const char, i.e.
> > you can do as you want with the pointer but you shouldn't change the
> > chars it points to.
> 
> Ermh, that's what I meant even if I was sloppy in my reply. And arguably
> freeing the bytes the pointer points at changes them, albeit subtly. And
> having a function return a pointer to const data is often an indication
> that the ownership of the data isn't transfered, i.e. you're not
> supposed to free it yourself.

I already applied the patch, but yes dropping the const would be a good
hint to callers that they now own that block of memory. Eric, can you pls
follow up with a fix up patch - drm-misc is non-rebasing?
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  reply	other threads:[~2016-08-15 13:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-15  0:02 [PATCH] drm: make drm_get_format_name thread-safe Eric Engestrom
2016-08-15  9:54 ` Jani Nikula
2016-08-15 12:59   ` Eric Engestrom
2016-08-15 13:13     ` Jani Nikula
2016-08-15 13:52       ` Daniel Vetter [this message]
2016-08-15 15:07         ` Eric Engestrom
2016-08-15 15:29         ` [FIXUP] drm: remove `const` attribute to hint at caller that they now own the memory Eric Engestrom
2016-08-16 11:04           ` Jani Nikula
2016-08-16 12:07             ` Daniel Vetter
2016-11-03 18:52 ` [Intel-gfx] [PATCH] drm: make drm_get_format_name thread-safe Rob Clark
2016-11-08  8:43   ` Daniel Vetter

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=20160815135207.GG6232@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=Flora.Cui@amd.com \
    --cc=Jerry.Zhang@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel.vetter@intel.com \
    --cc=david1.zhang@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=eric.engestrom@imgtec.com \
    --cc=eric@engestrom.ch \
    --cc=gustavo.padovan@collabora.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michel.daenzer@amd.com \
    --cc=tom.stdenis@amd.com \
    --cc=vitaly.prosyak@amd.com \
    --cc=yongjun_wei@trendmicro.com.cn \
    --cc=z.liuxinliang@hisilicon.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox