dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Eric Engestrom <eric@engestrom.ch>
To: Rob Clark <robdclark@gmail.com>
Cc: "Tom St Denis" <tom.stdenis@amd.com>,
	"Thomas Hellstrom" <thellstrom@vmware.com>,
	"Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>,
	"Intel Graphics Development" <intel-gfx@lists.freedesktop.org>,
	"Michel Dänzer" <michel.daenzer@amd.com>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Colin Ian King" <colin.king@canonical.com>,
	"Xinliang Liu" <z.liuxinliang@hisilicon.com>,
	"Emily Deng" <Emily.Deng@amd.com>,
	"Wei Yongjun" <yongjun_wei@trendmicro.com.cn>,
	"VMware Graphics" <linux-graphics-maintainer@vmware.com>,
	"Vitaly Prosyak" <vitaly.prosyak@amd.com>,
	"Junwei Zhang" <Jerry.Zhang@amd.com>,
	"Daniel Vetter" <daniel.vetter@intel.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: move allocation out of drm_get_format_name()
Date: Mon, 7 Nov 2016 00:47:13 +0000	[thread overview]
Message-ID: <20161107004713.GA26032@engestrom.ch> (raw)
In-Reply-To: <CAF6AEGt5Mz1S5h+pth2bz820ZirsXcEt0X7k5Z4P0q180ASg3A@mail.gmail.com>

On Sunday, 2016-11-06 08:03:47 -0500, Rob Clark wrote:
> On Sun, Nov 6, 2016 at 4:47 AM, Christian König
> <christian.koenig@amd.com> wrote:
> > Am 05.11.2016 um 17:49 schrieb Rob Clark:
> >>
> >> On Sat, Nov 5, 2016 at 12:38 PM, Eric Engestrom <eric@engestrom.ch> wrote:
> >>>
> >>> On Saturday, 2016-11-05 13:11:36 +0100, Christian König wrote:
> >>>>
> >>>> Am 05.11.2016 um 02:33 schrieb Eric Engestrom:
> >>>>>
> >>>>> +typedef char drm_format_name_buf[32];
> >>>>
> >>>> Please don't use a typedef for this, just define the maximum size of
> >>>> characters the function might write somewhere.
> >>>>
> >>>> See the kernel coding style as well:
> >>>>>
> >>>>> In general, a pointer, or a struct that has elements that can
> >>>>> reasonably
> >>>>> be directly accessed should **never** be a typedef.
> >>>
> >>> I would normally agree as I tend to hate typedefs ($DAYJOB {ab,mis}uses
> >>> them way too much), and your way was what I wrote at first, but Rob
> >>> Clark's
> >>> typedef idea makes it much harder for someone to allocate a buffer of
> >>> the wrong size, which IMO is good thing here.
> >>
> >> IMHO I would make a small test program to verify this actually helps
> >> the compiler catch problems.  And if it does, I would stick with it.
> >> The coding-style should be guidelines, not something that supersedes
> >> common sense / practicality.
> >
> >
> > Well completely agree that we should be able to question the coding style
> > rules, but when we do it we discuss this on a the mailing list first and
> > then start to use it in code. Not the other way around.
> 
> if I'm not mistaken, that is what we are doing ;-)
> 
> >>
> >> That is my $0.02 anyways.. if others vehemently disagree and want to
> >> dogmatically stick to the coding-style guidelines, ok then.  OTOH, if
> >> this approach doesn't help the compiler catch issues, then it isn't
> >> worth it.
> >
> >
> > Yeah, exactly that's the point. If I'm not completely mistaken the compiler
> > won't issue a warning here if you pass an array with the wrong size.
> >
> > I think you need something like "struct drm_format_name_buf { char str[32];
> > };" to trigger this.
> 
> hmm, actually the struct is a nice idea then if the compiler wouldn't
> catch the wrong-size-array

Sending the patch in a minute.

> 
> > apart from that is this function really called so often that using
> > kasprintf() is a problem here? or is there another motivation behind the
> > change?
> 
> two things trouble me about the kasprintf approach.. (ignoring the
> fact that atm it is not gfp_atomic)
> 1) you can't do drm_debug("format: %s\n", drm_get_format_name(..)) so
> it pulls the memory allocation and sprintf outside of the drm_debug
> check
> 2) seems awfully easy to forget the kfree...

I actually found a couple of these memory leaks while doing this patch,
look for files where i don't remove kfree :)
(eg. vmwgfx at the end of the patch)

> i wouldn't have even
> known that now you need to free the result (with some patches i'm
> working on) if it weren't for the fact that lockdep alerted me to the
> gfp_kernel allocation in atomic ctx ;-)
> 
> br,
> -r
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2016-11-07  0:47 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-04 15:32 [PATCH] drm: make drm_get_format_name atomic/irq safe again Rob Clark
2016-11-04 15:45 ` Rob Clark
2016-11-04 16:27 ` Ville Syrjälä
2016-11-04 17:12   ` Rob Clark
2016-11-04 17:32     ` Eric Engestrom
2016-11-04 17:33       ` [PATCH variant 1] " Eric Engestrom
2016-11-04 17:50       ` [PATCH] " Rob Clark
2016-11-04 18:13         ` Ville Syrjälä
2016-11-05  1:23         ` Eric Engestrom
2016-11-05  1:33           ` [PATCH] drm: move allocation out of drm_get_format_name() Eric Engestrom
2016-11-05  6:56             ` Thomas Hellstrom
2016-11-05 12:11             ` Christian König
2016-11-05 16:38               ` Eric Engestrom
2016-11-05 16:49                 ` Rob Clark
2016-11-06  9:47                   ` Christian König
2016-11-06 13:03                     ` Rob Clark
2016-11-07  0:47                       ` Eric Engestrom [this message]
2016-11-07  0:48                         ` [PATCH v2] " Eric Engestrom
2016-11-07  7:46                           ` Christian König
2016-11-07  8:10                           ` Jani Nikula
2016-11-07 17:12                             ` Eric Engestrom
2016-11-07 17:38                               ` Jani Nikula
2016-11-08 10:15                                 ` [Intel-gfx] " Daniel Vetter
2016-11-09  0:17                                   ` [PATCH v3] " Eric Engestrom
2016-11-09  1:09                                     ` [Intel-gfx] " Daniel Vetter
2016-11-09  1:13                                       ` Daniel Vetter
2016-11-09 11:42                                         ` Eric Engestrom
2016-11-09 13:13                                           ` [Intel-gfx] " Daniel Vetter
2016-11-09 16:59                                             ` Eric Engestrom
2016-11-10 10:03                                               ` Laurent Pinchart
2016-11-10 10:30                                                 ` [Intel-gfx] " Jani Nikula
2016-11-10 10:59                                                   ` Laurent Pinchart
2016-11-10 11:03                                                     ` Jani Nikula
2016-11-11  9:26                                               ` Daniel Vetter
2016-11-12  1:12                                                 ` [PATCH v4] " Eric Engestrom
2016-11-07 14:45                           ` [PATCH v2] " Rob Clark
2016-11-07 18:12                           ` Sinclair Yeh
2016-11-05  1:52           ` [PATCH] drm: make drm_get_format_name atomic/irq safe again Rob Clark

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=20161107004713.GA26032@engestrom.ch \
    --to=eric@engestrom.ch \
    --cc=Emily.Deng@amd.com \
    --cc=Flora.Cui@amd.com \
    --cc=Jerry.Zhang@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=colin.king@canonical.com \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavo.padovan@collabora.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=linux-graphics-maintainer@vmware.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michel.daenzer@amd.com \
    --cc=robdclark@gmail.com \
    --cc=thellstrom@vmware.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;
as well as URLs for NNTP newsgroup(s).