Re: [PATCH v2] drm/i915/quirk: Add quirk for devices that cannot be dimmed

2023-06-23 Thread Josh Triplett
On Thu, Jun 22, 2023 at 05:28:15PM +, Allen Ballway wrote:
> --- a/drivers/gpu/drm/i915/display/intel_backlight.c
> +++ b/drivers/gpu/drm/i915/display/intel_backlight.c
> @@ -1192,6 +1192,11 @@ static u32 get_backlight_min_vbt(struct 
> intel_connector *connector)
> 
>   drm_WARN_ON(&i915->drm, panel->backlight.pwm_level_max == 0);
> 
> + if (intel_has_quirk(i915, QUIRK_NO_DIM)) {
> + /* Cannot dim backlight, set minimum to hightest value */

Typo: s/hightest/highest/


[PATCH] i915: Add a Kconfig option to turn on i915.preliminary_hw_support by default

2013-08-14 Thread Josh Triplett
When building kernels for a preliminary hardware target, having to add a
kernel command-line option can prove inconvenient.  Add a Kconfig option
that changes the default of this option to 1.

Signed-off-by: Josh Triplett 
---

I dropped the indication of the default in the module parameter
documentation, but I could also change it to show the default for the
current kernel via ifdef.

 drivers/gpu/drm/Kconfig | 9 +
 drivers/gpu/drm/i915/i915_drv.c | 4 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index a7c54c8..35d57ed 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -168,6 +168,15 @@ config DRM_I915_KMS
  the driver to bind to PCI devices, which precludes loading things
  like intelfb.
 
+config DRM_I915_PRELIMINARY_HW_SUPPORT
+   bool "Enable preliminary support for prerelease Intel hardware by 
default"
+   depends on DRM_I915
+   help
+ Choose this option if you have prerelease Intel hardware and want the
+ i915 driver to support it by default.  You can enable such support at
+ runtime with the module option i915.preliminary_hw_support=1; this
+ option changes the default for that module option.
+
 config DRM_MGA
tristate "Matrox g200/g400"
depends on DRM && PCI
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 45b3c03..594e06c 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -118,10 +118,10 @@ module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, 
int, 0600);
 MODULE_PARM_DESC(i915_enable_ppgtt,
"Enable PPGTT (default: true)");
 
-unsigned int i915_preliminary_hw_support __read_mostly = 0;
+unsigned int i915_preliminary_hw_support __read_mostly = 
IS_ENABLED(CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT);
 module_param_named(preliminary_hw_support, i915_preliminary_hw_support, int, 
0600);
 MODULE_PARM_DESC(preliminary_hw_support,
-   "Enable preliminary hardware support. (default: false)");
+   "Enable preliminary hardware support.");
 
 int i915_disable_power_well __read_mostly = 1;
 module_param_named(disable_power_well, i915_disable_power_well, int, 0600);
-- 
1.8.4.rc2

___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH v5 06/24] Update MAINTAINERS and CREDITS files with amdkfd info

2014-11-08 Thread Josh Triplett
On Sat, Nov 08, 2014 at 08:37:27PM +0200, Oded Gabbay wrote:
>  CREDITS |  7 +++
>  MAINTAINERS | 10 ++
>  2 files changed, 17 insertions(+)

Given the wide variety of folks who patch CREDITS and MAINTAINERS, might
I suggest adding CREDITS and MAINTAINERS themselves to the MAINTAINERS
file (perhaps in the same entry as get_maintainer.pl), so that
get_maintainer.pl does not fall back to git history for them?

- Josh Triplett


[PATCH v5 06/24] Update MAINTAINERS and CREDITS files with amdkfd info

2014-11-08 Thread Josh Triplett
On Sat, Nov 08, 2014 at 12:49:29PM -0800, Joe Perches wrote:
> On Sat, 2014-11-08 at 11:01 -0800, Josh Triplett wrote:
> > On Sat, Nov 08, 2014 at 08:37:27PM +0200, Oded Gabbay wrote:
> > >  CREDITS |  7 +++
> > >  MAINTAINERS | 10 ++
> > >  2 files changed, 17 insertions(+)
> > 
> > Given the wide variety of folks who patch CREDITS and MAINTAINERS, might
> > I suggest adding CREDITS and MAINTAINERS themselves to the MAINTAINERS
> > file (perhaps in the same entry as get_maintainer.pl), so that
> > get_maintainer.pl does not fall back to git history for them?
> 
> Thanks but:
> 
> There is no MAINTAINERS/CREDITS maintainer.
> 
> I'm not volunteering.

Oh, I thought from all your work on file patterns and other such
improvements that you were the de-facto MAINTAINERS maintainer.

> Maybe you?

No thank you.

> But maybe something like this would help:
> 
> It has to have both an M: and an S: entry
> with maintained or supported to stop get_maintainers
> from doing a git history lookup.
> 
> ---
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0662378..584fd69 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -5881,6 +5881,12 @@ F: drivers/mailbox/
>  F:   include/linux/mailbox_client.h
>  F:   include/linux/mailbox_controller.h
>  
> +MAINTAINERS/CREDITS
> +M:   linux-kernel at vger.kernel.org
> +S:   Maintained
> +F:   MAINTAINERS
> +F:   CREDITS

Sending something only to LKML seems likely to go un-noticed.  I think
we need a better solution than this.

- Josh Triplett


[PATCH] i915: Add a Kconfig option to turn on i915.preliminary_hw_support by default

2013-08-13 Thread Josh Triplett
When building kernels for a preliminary hardware target, having to add a
kernel command-line option can prove inconvenient.  Add a Kconfig option
that changes the default of this option to 1.

Signed-off-by: Josh Triplett 
---

I dropped the indication of the default in the module parameter
documentation, but I could also change it to show the default for the
current kernel via ifdef.

 drivers/gpu/drm/Kconfig | 9 +
 drivers/gpu/drm/i915/i915_drv.c | 4 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index a7c54c8..35d57ed 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -168,6 +168,15 @@ config DRM_I915_KMS
  the driver to bind to PCI devices, which precludes loading things
  like intelfb.

+config DRM_I915_PRELIMINARY_HW_SUPPORT
+   bool "Enable preliminary support for prerelease Intel hardware by 
default"
+   depends on DRM_I915
+   help
+ Choose this option if you have prerelease Intel hardware and want the
+ i915 driver to support it by default.  You can enable such support at
+ runtime with the module option i915.preliminary_hw_support=1; this
+ option changes the default for that module option.
+
 config DRM_MGA
tristate "Matrox g200/g400"
depends on DRM && PCI
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 45b3c03..594e06c 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -118,10 +118,10 @@ module_param_named(i915_enable_ppgtt, i915_enable_ppgtt, 
int, 0600);
 MODULE_PARM_DESC(i915_enable_ppgtt,
"Enable PPGTT (default: true)");

-unsigned int i915_preliminary_hw_support __read_mostly = 0;
+unsigned int i915_preliminary_hw_support __read_mostly = 
IS_ENABLED(CONFIG_DRM_I915_PRELIMINARY_HW_SUPPORT);
 module_param_named(preliminary_hw_support, i915_preliminary_hw_support, int, 
0600);
 MODULE_PARM_DESC(preliminary_hw_support,
-   "Enable preliminary hardware support. (default: false)");
+   "Enable preliminary hardware support.");

 int i915_disable_power_well __read_mostly = 1;
 module_param_named(disable_power_well, i915_disable_power_well, int, 0600);
-- 
1.8.4.rc2



Re: [PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup

2013-03-11 Thread Josh Triplett
On Mon, Mar 11, 2013 at 09:30:40PM +0200, Alexandru Gheorghiu wrote:
> Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
> This patch was found using coccinelle.
> 
> Signed-off-by: Alexandru Gheorghiu 
> ---
>  drivers/gpu/drm/i915/intel_dp.c |3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index f61cb79..a3fdd65 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -2335,11 +2335,10 @@ intel_dp_get_edid(struct drm_connector *connector, 
> struct i2c_adapter *adapter)
>   return NULL;
>  
>   size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
> - edid = kmalloc(size, GFP_KERNEL);
> + edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
>   if (!edid)
>   return NULL;
>  
> - memcpy(edid, intel_connector->edid, size);
>   return edid;
>   }

With this change, the conditional no longer makes sense; this should
just "return kmemdup(...);".

That suggests an obvious further cleanup that coccinelle could easily
handle:

if (!foo)
return NULL;
return foo;

should become just "return foo;".  And you might then want to check for
variables used *only* to capture a return value and immediately
returned, and eliminate them.

- Josh Triplett
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 0/9] use c99 initializers in structures

2014-08-23 Thread Josh Triplett
On Sat, Aug 23, 2014 at 01:20:22PM +0200, Julia Lawall wrote:
> These patches add labels in the initializations of structure fields (c99
> initializers).  The complete semantic patch thta makes this change is shown
> below.  This rule ignores cases where the initialization is just 0 or NULL,
> where some of the fields already use labels, and where there are nested
> structures.

I responded to patches 6 and 8 with comments; for the rest (1-5, 7, 9):
Reviewed-by: Josh Triplett 


[PATCH 6/9] drm: use c99 initializers in structures

2014-08-23 Thread Josh Triplett
On Sat, Aug 23, 2014 at 01:20:28PM +0200, Julia Lawall wrote:
> From: Julia Lawall 
> 
> Use c99 initializers for structures.
> 
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
> 
> // 
> @decl@
> identifier i1,fld;
> type T;
> field list[n] fs;
> @@
> 
> struct i1 {
>  fs
>  T fld;
>  ...};
> 
> @bad@
> identifier decl.i1,i2;
> expression e;
> initializer list[decl.n] is;
> @@
> 
> struct i1 i2 = { is,
> + .fld = e
> - e
>  ,...};
> // 
> 
> Signed-off-by: Julia Lawall 

For this patch, I think it would make sense to drop
initializations of preferred/quirks/modes to 0, since a designated
initializer may skip fields to leave them initialized to 0.

With that change:
Reviewed-by: Josh Triplett 

> 
>  drivers/gpu/drm/sti/sti_vtac.c |   12 ++--
>  drivers/gpu/drm/drm_edid.c |   34 +-
>  2 files changed, 35 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/sti/sti_vtac.c b/drivers/gpu/drm/sti/sti_vtac.c
> index 82a51d4..4576536 100644
> --- a/drivers/gpu/drm/sti/sti_vtac.c
> +++ b/drivers/gpu/drm/sti/sti_vtac.c
> @@ -56,8 +56,16 @@ struct sti_vtac_mode {
>   u32 phyts_per_pixel;
>  };
>  
> -static const struct sti_vtac_mode vtac_mode_main = {0x2, 0x2, VTAC_5_PPP};
> -static const struct sti_vtac_mode vtac_mode_aux = {0x1, 0x0, VTAC_17_PPP};
> +static const struct sti_vtac_mode vtac_mode_main = {
> + .vid_in_width = 0x2,
> + .phyts_width = 0x2,
> + .phyts_per_pixel = VTAC_5_PPP
> +};
> +static const struct sti_vtac_mode vtac_mode_aux = {
> + .vid_in_width = 0x1,
> + .phyts_width = 0x0,
> + .phyts_per_pixel = VTAC_17_PPP
> +};
>  
>  /**
>   * VTAC structure
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 1dbf3bc..a28c330 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -2103,7 +2103,11 @@ static int
>  add_inferred_modes(struct drm_connector *connector, struct edid *edid)
>  {
>   struct detailed_mode_closure closure = {
> - connector, edid, 0, 0, 0
> + .connector = connector,
> + .edid = edid,
> + .preferred = 0,
> + .quirks = 0,
> + .modes = 0
>   };
>  
>   if (version_greater(edid, 1, 0))
> @@ -2169,7 +2173,11 @@ add_established_modes(struct drm_connector *connector, 
> struct edid *edid)
>   ((edid->established_timings.mfg_rsvd & 0x80) << 9);
>   int i, modes = 0;
>   struct detailed_mode_closure closure = {
> - connector, edid, 0, 0, 0
> + .connector = connector,
> + .edid = edid,
> + .preferred = 0,
> + .quirks = 0,
> + .modes = 0
>   };
>  
>   for (i = 0; i <= EDID_EST_TIMINGS; i++) {
> @@ -2227,7 +2235,11 @@ add_standard_modes(struct drm_connector *connector, 
> struct edid *edid)
>  {
>   int i, modes = 0;
>   struct detailed_mode_closure closure = {
> - connector, edid, 0, 0, 0
> + .connector = connector,
> + .edid = edid,
> + .preferred = 0,
> + .quirks = 0,
> + .modes = 0
>   };
>  
>   for (i = 0; i < EDID_STD_TIMINGS; i++) {
> @@ -2313,7 +2325,11 @@ static int
>  add_cvt_modes(struct drm_connector *connector, struct edid *edid)
>  {
>   struct detailed_mode_closure closure = {
> - connector, edid, 0, 0, 0
> + .connector = connector,
> + .edid = edid,
> + .preferred = 0,
> + .quirks = 0,
> + .modes = 0
>   };
>  
>   if (version_greater(edid, 1, 2))
> @@ -2357,11 +2373,11 @@ add_detailed_modes(struct drm_connector *connector, 
> struct edid *edid,
>  u32 quirks)
>  {
>   struct detailed_mode_closure closure = {
> - connector,
> - edid,
> - 1,
> - quirks,
> - 0
> + .connector = connector,
> + .edid = edid,
> + .preferred = 1,
> + .quirks = quirks,
> + .modes = 0
>   };
>  
>   if (closure.preferred && !version_greater(edid, 1, 3))
> 


[PATCH 82/85] drivers: gpu: Mark functions as static in vmwgfx_kms.c

2014-01-07 Thread Josh Triplett
On Tue, Jan 07, 2014 at 11:21:12AM +0100, Jakob Bornecrantz wrote:
> On Mon, Jan 6, 2014 at 5:48 PM, Rashika Kheria  
> wrote:
> > Mark functions as static because they are not used outside the file
> > drm/vmwgfx/vmwgfx_kms.c.
> >
> > This eliminates the following warnings in drm/vmwgfx/vmwgfx_kms.c:
> > drivers/gpu/drm/vmwgfx/vmwgfx_kms.c:43:6: warning: no previous prototype 
> > for ?vmw_clip_cliprects? [-Wmissing-prototypes]
> > drivers/gpu/drm/vmwgfx/vmwgfx_kms.c:426:6: warning: no previous prototype 
> > for ?vmw_framebuffer_surface_destroy? [-Wmissing-prototypes]
> > drivers/gpu/drm/vmwgfx/vmwgfx_kms.c:592:5: warning: no previous prototype 
> > for ?vmw_framebuffer_surface_dirty? [-Wmissing-prototypes]
> > drivers/gpu/drm/vmwgfx/vmwgfx_kms.c:757:6: warning: no previous prototype 
> > for ?vmw_framebuffer_dmabuf_destroy? [-Wmissing-prototypes]
> > drivers/gpu/drm/vmwgfx/vmwgfx_kms.c:943:5: warning: no previous prototype 
> > for ?vmw_framebuffer_dmabuf_dirty? [-Wmissing-prototypes]
> > drivers/gpu/drm/vmwgfx/vmwgfx_kms.c:1666:5: warning: no previous prototype 
> > for ?vmw_du_update_layout? [-Wmissing-prototypes]
> >
> > Signed-off-by: Rashika Kheria 
> > Reviewed-by: Josh Triplett 
> > ---
> >  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |   12 ++--
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> 
> This and patch 83, 84, 85 are
> Reviewed-by: Jakob Bornecrantz 

Can you take them through your tree, or are you expecting them to follow
another path?

- Josh Triplett


[PATCH 22/85] drivers: gpu: Mark functions as static in radeon_device.c

2014-01-08 Thread Josh Triplett
On Wed, Jan 08, 2014 at 11:40:28AM -0500, Alex Deucher wrote:
> On Mon, Jan 6, 2014 at 10:21 AM, Rashika Kheria
>  wrote:
> > Mark functions radeon_doorbell_init() and radeon_doorbell_fini() as
> > static in drm/radeon/radeon_device.c because they are not used outside
> > this file.
> >
> > This eliminates the following warning in drm/radeon/radeon_device.c:
> > drivers/gpu/drm/radeon/radeon_device.c:252:5: warning: no previous 
> > prototype for ?radeon_doorbell_init? [-Wmissing-prototypes]
> > drivers/gpu/drm/radeon/radeon_device.c:281:6: warning: no previous 
> > prototype for ?radeon_doorbell_fini? [-Wmissing-prototypes]
> >
> > Signed-off-by: Rashika Kheria 
> > Reviewed-by: Josh Triplett 
> 
> I've pulled in a subset of these patches:
> http://cgit.freedesktop.org/~agd5f/linux/log/?h=drm-next-3.14-wip
> I held off on some of the others as I'd rather fix up the headers
> properly rather than just cramming everything in radeon.h or
> radeon-asic.h for now.

Can you elaborate on which patches are putting functions in the wrong
header, and what header you'd prefer to see them in?

- Josh Triplett


[PATCH 9/9] [media] mm: Move get_vaddr_frames() behind a config option

2015-06-10 Thread Josh Triplett
On Wed, Jun 10, 2015 at 06:20:52AM -0300, Mauro Carvalho Chehab wrote:
> From: Jan Kara 
> 
> get_vaddr_frames() is used by relatively rare drivers so hide it and the
> related functions behind a config option that is selected only by
> drivers that need the infrastructure.
> 
> Suggested-by: Andrew Morton 
> 
> Signed-off-by: Jan Kara 
> Signed-off-by: Hans Verkuil 
> Signed-off-by: Mauro Carvalho Chehab 

Seems sensible to me.

Since this patch makes the kernel smaller, can you include the delta
from bloat-o-meter between allnoconfig with and without this patch?

Also, I assume you've compile-tested the kernel with allyesconfig minus
the three options that now have "select FRAME_VECTOR", to make sure it
builds?

>  create mode 100644 mm/frame_vector.c
> 
> diff --git a/drivers/gpu/drm/exynos/Kconfig b/drivers/gpu/drm/exynos/Kconfig
> index 0a6780367d28..fc678289cf79 100644
> --- a/drivers/gpu/drm/exynos/Kconfig
> +++ b/drivers/gpu/drm/exynos/Kconfig
> @@ -71,6 +71,7 @@ config DRM_EXYNOS_VIDI
>  config DRM_EXYNOS_G2D
>   bool "Exynos DRM G2D"
>   depends on DRM_EXYNOS && !VIDEO_SAMSUNG_S5P_G2D
> + select FRAME_VECTOR
>   help
> Choose this option if you want to use Exynos G2D for DRM.
>  
> diff --git a/drivers/media/platform/omap/Kconfig 
> b/drivers/media/platform/omap/Kconfig
> index dc2aaab54aef..217d613b0fe7 100644
> --- a/drivers/media/platform/omap/Kconfig
> +++ b/drivers/media/platform/omap/Kconfig
> @@ -10,6 +10,7 @@ config VIDEO_OMAP2_VOUT
>   select OMAP2_DSS if HAS_IOMEM && ARCH_OMAP2PLUS
>   select OMAP2_VRFB if ARCH_OMAP2 || ARCH_OMAP3
>   select VIDEO_OMAP2_VOUT_VRFB if VIDEO_OMAP2_VOUT && OMAP2_VRFB
> + select FRAME_VECTOR
>   default n
>   ---help---
> V4L2 Display driver support for OMAP2/3 based boards.
> diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig
> index f7a01a72eb9e..f38f6e387f04 100644
> --- a/drivers/media/v4l2-core/Kconfig
> +++ b/drivers/media/v4l2-core/Kconfig
> @@ -73,6 +73,7 @@ config VIDEOBUF2_CORE
>  
>  config VIDEOBUF2_MEMOPS
>   tristate
> + select FRAME_VECTOR
>  
>  config VIDEOBUF2_DMA_CONTIG
>   tristate
> diff --git a/mm/Kconfig b/mm/Kconfig
> index 390214da4546..2ca52e9986f0 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -635,3 +635,6 @@ config MAX_STACK_SIZE_MB
> changed to a smaller value in which case that is used.
>  
> A sane initial value is 80 MB.
> +
> +config FRAME_VECTOR
> + bool
> diff --git a/mm/Makefile b/mm/Makefile
> index 98c4eaeabdcb..be5d5c866305 100644
> --- a/mm/Makefile
> +++ b/mm/Makefile
> @@ -78,3 +78,4 @@ obj-$(CONFIG_CMA)   += cma.o
>  obj-$(CONFIG_MEMORY_BALLOON) += balloon_compaction.o
>  obj-$(CONFIG_PAGE_EXTENSION) += page_ext.o
>  obj-$(CONFIG_CMA_DEBUGFS) += cma_debug.o
> +obj-$(CONFIG_FRAME_VECTOR) += frame_vector.o
> diff --git a/mm/frame_vector.c b/mm/frame_vector.c
> new file mode 100644
> index ..31a2bd5f41d5
> --- /dev/null
> +++ b/mm/frame_vector.c
> @@ -0,0 +1,232 @@
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * get_vaddr_frames() - map virtual addresses to pfns
> + * @start:   starting user address
> + * @nr_frames:   number of pages / pfns from start to map
> + * @write:   whether pages will be written to by the caller
> + * @force:   whether to force write access even if user mapping is
> + *   readonly. See description of the same argument of
> + get_user_pages().
> + * @vec: structure which receives pages / pfns of the addresses mapped.
> + *   It should have space for at least nr_frames entries.
> + *
> + * This function maps virtual addresses from @start and fills @vec structure
> + * with page frame numbers or page pointers to corresponding pages (choice
> + * depends on the type of the vma underlying the virtual address). If @start
> + * belongs to a normal vma, the function grabs reference to each of the pages
> + * to pin them in memory. If @start belongs to VM_IO | VM_PFNMAP vma, we 
> don't
> + * touch page structures and the caller must make sure pfns aren't reused for
> + * anything else while he is using them.
> + *
> + * The function returns number of pages mapped which may be less than
> + * @nr_frames. In particular we stop mapping if there are more vmas of
> + * different type underlying the specified range of virtual addresses.
> + * When the function isn't able to map a single page, it returns error.
> + *
> + * This function takes care of grabbing mmap_sem as necessary.
> + */
> +int get_vaddr_frames(unsigned long start, unsigned int nr_frames,
> +  bool write, bool force, struct frame_vector *vec)
> +{
> + struct mm_struct *mm = current->mm;
> + struct vm_area_struct *vma;
> + int ret = 0;
> + int err;
> + int locked;
> +
> + if (nr_frames == 0)
> + return 0;
> +
> + if (WARN_ON_ONCE(nr_frames > vec->nr_allocated))
> 

[PATCH] drivers: gpu: drm: i915: Replaced calls to kmalloc & memcpy with kmemdup

2013-03-11 Thread Josh Triplett
On Mon, Mar 11, 2013 at 09:30:40PM +0200, Alexandru Gheorghiu wrote:
> Replaced calls to kmalloc followed by memcpy with a single call to kmemdup.
> This patch was found using coccinelle.
> 
> Signed-off-by: Alexandru Gheorghiu 
> ---
>  drivers/gpu/drm/i915/intel_dp.c |3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index f61cb79..a3fdd65 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -2335,11 +2335,10 @@ intel_dp_get_edid(struct drm_connector *connector, 
> struct i2c_adapter *adapter)
>   return NULL;
>  
>   size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
> - edid = kmalloc(size, GFP_KERNEL);
> + edid = kmemdup(intel_connector->edid, size, GFP_KERNEL);
>   if (!edid)
>   return NULL;
>  
> - memcpy(edid, intel_connector->edid, size);
>   return edid;
>   }

With this change, the conditional no longer makes sense; this should
just "return kmemdup(...);".

That suggests an obvious further cleanup that coccinelle could easily
handle:

if (!foo)
return NULL;
return foo;

should become just "return foo;".  And you might then want to check for
variables used *only* to capture a return value and immediately
returned, and eliminate them.

- Josh Triplett