linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] use devm_ functions
@ 2012-08-03 15:40 Damien Cassou
  2012-08-03 15:40 ` [PATCH 1/5] drivers/video/epson1355fb.c: " Damien Cassou
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Damien Cassou @ 2012-08-03 15:40 UTC (permalink / raw)
  To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel

These patches introduce devm_ functions in some video drivers. They have been
generated using Coccinelle (http://coccinelle.lip6.fr/) and the following
semantic patch:

virtual after_start

virtual returned
virtual returnedDup
virtual arg
virtual argDup
virtual all_args
virtual get
virtual nonull

virtual report

// ---------------------------------------------------------------------
// find functions

@plat depends on !after_start@
identifier i,pfn,rfn;
position p;
@@

struct platform_driver i@p = {
  .probe = pfn,
  .remove = (<+...rfn...+>),
};

// ---------------------------------------------------------------------
// set up iteration

@initialize:ocaml@

let reporting = ref false

type ret =
     UseReturned | UseReturned2 of string | UseReturnedDup | UseReturnedNN
     | UseArg | UseArgDup | UseArgNN | UseAllArgs | UseGet

let add pfn rfn alloc free devm_alloc file rule =
   let it = new iteration() in
   it#set_files [file];
   it#add_virtual_rule After_start;
   (match rule with
      UseReturned -> it#add_virtual_rule Returned
    | UseReturnedNN -> it#add_virtual_rule Returned; it#add_virtual_rule Nonull
    | UseReturnedDup -> it#add_virtual_rule ReturnedDup
    | UseReturned2(free) -> it#add_virtual_rule Returned;
      it#add_virtual_identifier Second_free free
    | UseArg -> it#add_virtual_rule Arg
    | UseArgNN -> it#add_virtual_rule Arg; it#add_virtual_rule Nonull
    | UseArgDup -> it#add_virtual_rule ArgDup
    | UseAllArgs -> it#add_virtual_rule All_args
    | UseGet -> it#add_virtual_rule Get);
   if !reporting then it#add_virtual_rule Report;
   if not (pfn="") then it#add_virtual_identifier Pfn pfn;
   if not (rfn="") then it#add_virtual_identifier Rfn rfn;
   if not (alloc="") then it#add_virtual_identifier Alloc alloc;
   if not (free="") then it#add_virtual_identifier Free free;
   if not (devm_alloc="") then it#add_virtual_identifier Devm_alloc devm_alloc;
   it#register()

@script:ocaml depends on report && !after_start@
@@
reporting := true

@script:ocaml@
pfn << plat.pfn;
rfn << plat.rfn;
p << plat.p;
@@

let file = (List.hd p).file in
add pfn rfn "kmalloc" "kfree" "devm_kzalloc" file UseReturned;
add pfn rfn "kzalloc" "kfree" "devm_kzalloc" file UseReturned;
add pfn rfn "ioremap" "iounmap" "devm_ioremap" file UseReturned;
add pfn rfn "ioremap_nocache" "iounmap" "devm_ioremap_nocache" file
   UseReturned;

add pfn rfn "clk_get" "clk_put" "devm_clk_get" file UseReturnedDup;
add pfn rfn "clk_get" "clk_put" "devm_clk_get_bad" file UseReturnedNN;

add pfn rfn "usb_get_phy" "usb_put_phy" "devm_usb_get_phy" file UseReturned;

add pfn rfn "pinctrl_get" "pinctrl_put" "devm_pinctrl_get" file UseReturned;
add pfn rfn "pinctrl_get_select_default" "pinctrl_put"
            "devm_pinctrl_get_select_default" file UseReturned;

add pfn rfn "regulator_get" "regulator_put" "devm_regulator_get"
            file UseReturned;
add pfn rfn "regulator_bulk_get" "regulator_bulk_free"
            "devm_regulator_bulk_get" file UseAllArgs;

add pfn rfn "gpio_request" "gpio_free" "devm_gpio_request" file UseArg;
add pfn rfn "gpio_request_one" "gpio_free" "devm_gpio_request_one" file UseArg;

(*
add pfn rfn "request_irq" "free_irq" "devm_request_irq" file UseArg;
add pfn rfn "request_threaded_irq" "free_irq" "devm_request_threaded_irq" file
  UseArg;
*)
add pfn rfn "dma_alloc_coherent" "dma_free_coherent" "dmam_alloc_coherent"
  file UseReturnedDup;
add pfn rfn "dma_alloc_noncoherent" "dma_free_noncoherent"
  "dmam_alloc_noncoherent" file UseReturnedDup;
add pfn rfn "dma_alloc_coherent" "dma_free_coherent" "dmam_alloc_coherent_bad"
  file UseReturnedNN;
add pfn rfn "dma_alloc_noncoherent" "dma_free_noncoherent"
  "dmam_alloc_noncoherent_bad" file UseReturnedNN;

(* several possibilities... *)
add pfn rfn "request_region" "release_region" "devm_request_region" file
  UseGet;
add pfn rfn "request_mem_region" "release_mem_region"
  "devm_request_mem_region" file UseGet;
add pfn rfn "request_region" "release_region" "devm_request_region" file
  UseArg;
add pfn rfn "request_mem_region" "release_mem_region"
  "devm_request_mem_region" file UseArg;
(* fix a bug at the same time *)
add pfn rfn "request_region" "release_resource" "devm_request_region" file
  (UseReturned2("kfree"));
add pfn rfn "request_mem_region" "release_resource"
  "devm_request_mem_region" file (UseReturned2("kfree"));
add pfn rfn "ioport_map" "ioport_unmap" "devm_ioport_map" file UseReturned

// ---------------------------------------------------------------------
// process the initial definition of the probe function

@preprobe@
identifier virtual.pfn;
position p;
@@

pfn@p(...) { ... }

@probe@
identifier pfn;
position preprobe.p;
@@

pfn@p(...) { ... }

@labelled_return@
identifier probe.pfn,l;
expression e;
@@

pfn(...) { <+... l: return e; ...+> }

// ---------------------------------------------------------------------
// transform functions where free uses the result

@prb depends on returned exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free,virtual.second_free;
expression x,y,e,a;
position p1,p2,p3;
type T1,T2,T3;
@@

pfn(struct platform_device *pdev) { ... when any
x = (T1)alloc@p1(a,...)
<... when strict
     when any
     when forall
(
y = x;
... when != y = e
    when != &y
free@p2(...,(T2)y,...);
... when != x
    when != y
second_free@p3(...,(T3)y,...);
|
y = x;
... when != y = e
    when != &y
free@p2(...,(T2)y,...);
|
free@p2(...,(T2)x,...);
... when != x
second_free@p3(...,(T3)x,...);
|
free@p2(...,(T2)x,...);
)
...>
}

@script:ocaml@
a << prb.a;
@@

if a = "NULL" then Coccilib.include_match false

@reme exists@
identifier virtual.rfn,virtual.free;
expression prb.x,prb.y;
type T;
@@

rfn(...) { ... free(...,(T)\(x\|y\),...); ... }

@rem depends on reme@
identifier virtual.rfn,virtual.free,virtual.second_free;
expression prb.x,prb.y;
position p4,p5;
type T,T1;
@@

rfn(...) {
<... when strict
(
free@p4(...,(T)\(x\|y\),...);
... when != x
second_free@p5(...,(T1)\(x\|y\),...);
|
free@p4(...,(T)\(x\|y\),...);
)
...>
}

@bad@
identifier virtual.free;
expression prb.x,prb.y;
position p != {prb.p2,rem.p4};
type T;
@@

free@p(...,(T)\(x\|y\),...)

@modif depends on rem && !bad && !report@
expression x;
identifier prb.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
identifier virtual.second_free;
expression list args;
position prb.p1,prb.p2,prb.p3,rem.p4,rem.p5;
type T;
@@

(
- free@p2(...);
|
- second_free@p3(...);
|
- free@p4(...);
|
- second_free@p5(...);
|
  x =
- alloc@p1(
+ devm_alloc(&pdev->dev,
    args)
|
  x =
- (T)alloc@p1(
+ (T)devm_alloc(&pdev->dev,
    args)
)

@script:python depends on rem && !bad && report@
p1 << prb.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)

// ---------------------------------------------------------------------
// transform functions where free uses the result
// special case for clk where don't add &pdev->dev

@prbdup depends on returnedDup exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free,virtual.second_free;
expression x,y,e;
expression list args;
position p1,p2,p3;
type T1,T2,T3;
@@

pfn(struct platform_device *pdev) { ... when any
x = (T1)alloc@p1(&pdev->dev,args)
<... when strict
     when any
     when forall
(
y = x;
... when != y = e
    when != &y
free@p2(...,(T2)y,...);
... when != x
    when != y
second_free@p3(...,(T3)y,...);
|
y = x;
... when != y = e
    when != &y
free@p2(...,(T2)y,...);
|
free@p2(...,(T2)x,...);
... when != x
second_free@p3(...,(T3)x,...);
|
free@p2(...,(T2)x,...);
)
...>
}

@remdupe exists@
identifier virtual.rfn,virtual.free;
expression prbdup.x,prbdup.y;
type T;
@@

rfn(...) { ... free(...,(T)\(x\|y\),...); ... }

@remdup depends on remdupe@
identifier virtual.rfn,virtual.free,virtual.second_free;
expression prbdup.x,prbdup.y;
position p4,p5;
type T,T1;
@@

rfn(...) {
<... when strict
(
free@p4(...,(T)\(x\|y\),...);
... when != x
second_free@p5(...,(T1)\(x\|y\),...);
|
free@p4(...,(T)\(x\|y\),...);
)
...>
}

@baddup@
identifier virtual.free;
expression prbdup.x,prbdup.y;
position p != {prbdup.p2,remdup.p4};
type T;
@@

free@p(...,(T)\(x\|y\),...)

@modifdup depends on remdup && !baddup && !report@
expression x;
identifier virtual.alloc,virtual.free,virtual.devm_alloc;
identifier virtual.second_free;
expression list args;
position prbdup.p1,prbdup.p2,prbdup.p3,remdup.p4,remdup.p5;
type T;
@@

(
- free@p2(...);
|
- second_free@p3(...);
|
- free@p4(...);
|
- second_free@p5(...);
|
  x =
- alloc@p1
+ devm_alloc
    (args)
|
  x =
- (T)alloc@p1
+ (T)devm_alloc
    (args)
)

@script:python depends on remdup && !baddup && report@
p1 << prbdup.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)

// ---------------------------------------------------------------------
// transform functions where free uses the first argument

@prbx depends on arg exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression x,y,e;
expression list args;
position p1,p2;
@@

pfn(struct platform_device *pdev) { ... when any
alloc@p1(x,args)
<... when strict
     when any
     when forall
(
y = x;
... when != y = e
    when != &y
free@p2(y,...);
|
free@p2(x,...)
)
...>
}

@script:ocaml@
x << prbx.x;
@@

if x = "NULL" then Coccilib.include_match false

@remxe exists@
identifier virtual.rfn, virtual.free;
expression prbx.x,prbx.y;
@@

rfn(...) { ... free(\(x\|y\),...); ... }

@remx depends on remxe@
identifier virtual.rfn, virtual.free;
expression prbx.x,prbx.y;
position p3;
@@

rfn(...) {
<... when strict
free@p3(\(x\|y\),...)
...>
}

@badx@
identifier virtual.free;
expression prbx.x,prbx.y;
position p != {prbx.p2,remx.p3};
@@

free@p(\(x\|y\),...)

@modifx depends on remx && !badx && !report@
expression x;
identifier prbx.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
expression list args;
position prbx.p1,prbx.p2,remx.p3;
@@

(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1(
+ devm_alloc(&pdev->dev,
   x,args)
)

@script:python depends on remx && !badx && report@
p1 << prbx.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)

// ---------------------------------------------------------------------
// transform functions where free uses the first argument

@prbxdup depends on argDup exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression y,e;
expression list args;
position p1,p2;
@@

pfn(struct platform_device *pdev) { ... when any
alloc@p1(&pdev->dev,args)
<... when strict
     when any
     when forall
(
y = &pdev->dev;
... when != y = e
    when != &y
free@p2(y,...);
|
free@p2(&pdev->dev,...)
)
...>
}

@remxedup exists@
identifier virtual.rfn, virtual.free, prbxdup.pdev;
expression prbxdup.y;
@@

rfn(...) { ... free(\(&pdev->dev\|y\),...); ... }

@remxdup depends on remxedup@
identifier virtual.rfn, virtual.free, prbxdup.pdev;
expression prbxdup.y;
position p3;
@@

rfn(...) {
<... when strict
free@p3(\(&pdev->dev\|y\),...)
...>
}

@badxdup@
identifier virtual.free,prbxdup.pdev;
expression prbxdup.y;
position p != {prbxdup.p2,remxdup.p3};
@@

free@p(\(&pdev->dev\|y\),...)

@modifxdup depends on remxdup && !badxdup && !report@
identifier virtual.alloc,virtual.free,virtual.devm_alloc;
expression list args;
position prbxdup.p1,prbxdup.p2,remxdup.p3;
@@

(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1
+ devm_alloc
   (args)
)

@script:python depends on remxdup && !badxdup && report@
p1 << prbxdup.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)

// ---------------------------------------------------------------------
// transform functions where free uses all arguments

@prbax depends on all_args exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression list x;
position p1,p2;
@@

pfn(struct platform_device *pdev) { ... when any
alloc@p1(x)
<... when strict
     when any
     when forall
free@p2(x)
...>
}

@remaxe exists@
identifier virtual.rfn, virtual.free;
expression list prbax.x;
@@

rfn(...) { ... free(x); ... }

@remax depends on remaxe@
identifier virtual.rfn, virtual.free;
expression list prbax.x;
position p3;
@@

rfn(...) {
<... when strict
free@p3(x)
...>
}

@badax@
identifier virtual.free;
expression list prbax.x;
position p != {prbax.p2,remax.p3};
@@

free@p(x)

@modifax depends on remax && !badax && !report@
identifier prbax.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
expression list x;
position prbax.p1,prbax.p2,remax.p3;
@@

(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1(
+ devm_alloc(&pdev->dev,
   x)
)

@script:python depends on remax && !badax && report@
p1 << prbax.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)

// ---------------------------------------------------------------------
// transform functions where free uses the result of platform_get_resource

@prbg depends on get exists@
identifier probe.pfn,pdev,virtual.alloc,virtual.free;
expression x,y,e;
expression list args;
position p1,p2;
@@

pfn(struct platform_device *pdev) { ... when any
alloc@p1(x,args)
<... when strict
     when any
     when forall
(
y = x;
... when != y = e
    when != &y
free@p2(y,...);
|
free@p2(x,...)
)
...>
}

@remge exists@
identifier virtual.rfn, virtual.free;
identifier z;
identifier pdev;
expression e,n;
@@

rfn(struct platform_device *pdev) { ... when any
z = platform_get_resource(pdev, IORESOURCE_MEM, n)
... when != z = e
    when != &z
free(z->start,...)
...
}

@remg depends on remge@
identifier virtual.rfn, virtual.free;
identifier z;
identifier pdev;
position p3;
expression e,n;
@@

rfn(struct platform_device *pdev) {
<... when strict
z = platform_get_resource(pdev, IORESOURCE_MEM, n)
... when strict
    when != z = e
    when != &z
free@p3(z->start,...)
...>
}

@badg@
identifier virtual.free;
position p != {prbg.p2,remg.p3};
@@

free@p(...)

@modifg depends on remg && !badg && !report@
expression x;
identifier prbg.pdev,virtual.alloc,virtual.free,virtual.devm_alloc;
expression list args;
position prbg.p1,prbg.p2,remg.p3;
@@

(
- free@p2(...);
|
- free@p3(...);
|
- alloc@p1(
+ devm_alloc(&pdev->dev,
   x,args)
)

@script:python depends on remg && !badg && report@
p1 << prbg.p1;
alloc << virtual.devm_alloc;
@@
msg = "WARNING opportunity for %s" % (alloc)
coccilib.report.print_report(p1[0], msg)

// ---------------------------------------------------------------------
// cleanup, if the drvdata was only used to enable the free
// probably only relevant for kmalloc/kzalloc

@dclean depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn, pdev, i;
type T;
@@

rfn(struct platform_device *pdev) { ...
(
- T i = platform_get_drvdata(pdev);
|
- T i = dev_get_drvdata(&pdev->drv);
|
- T i;
  ... when != i
(
- i = platform_get_drvdata(pdev);
|
- i = dev_get_drvdata(&pdev->drv);
)
)
... when != i
}

@rclean depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn, pdev, i;
type T;
@@

rfn(struct platform_device *pdev) { ...
(
- T i = platform_get_resource(pdev,...);
|
- T i;
  ... when != i
- i = platform_get_resource(pdev,...);
)
... when != i
}

// ---------------------------------------------------------------------
// cleanup empty ifs, etc

@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier probe.pfn;
@@

pfn(...) { <...
- if (...) {}
...> }

@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn;
@@

rfn(...) { <...
- if (...) {}
...> }

@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier probe.pfn;
expression ret,e;
@@

pfn(...) { <...
+ return
- ret =
 e;
- return ret;
...> }

@depends on modif || modifdup || modifx || modifxdup || modifax || modifg@
identifier virtual.rfn;
expression ret,e;
@@

rfn(...) { <...
+ return
- ret =
 e;
- return ret;
...> }

// ---------------------------------------------------------------------

// this is likely to leave dead code, if l: is preceded by a return
// because we are control-flow based, there is no way to match on that
@depends on labelled_return && (modif || modifdup || modifx || modifxdup || modifax || modifg)@
identifier l,l1,l2;
expression e;
statement S;
identifier probe.pfn;
identifier i;
statement S1,S2;
@@

pfn(...) { <...
- goto l;
+ goto l2;
...
-l:
<... when != S
     when any
l1:
...>
l2:
(
 (<+...i...+>);
|
 if (...) S1 else S2
|
 while (...) S1
|
 for (...;...;...) S1
|
 return e;
)
...> }

@depends on !labelled_return && (modif || modifdup || modifx || modifxdup || modifax || modifg)@
identifier l,l1,l2;
expression e;
statement S;
identifier probe.pfn;
identifier i;
statement S1,S2;
@@

pfn(...) { <...
(
- goto l;
+ goto l2;
...
-l:
<... when != S
     when any
l1:
...>
l2:
(
 (<+...i...+>);
|
 if (...) S1 else S2
|
 while (...) S1
|
 for (...;...;...) S1
)
|
- goto l;
+ return e;
...
-l:
<... when != S
     when any
l1:
...>
return e;
)
...> }

@depends on !labelled_return && (modif || modifdup || modifx || modifxdup || modifax || modifg)@
expression e1,e2;
identifier probe.pfn;
@@

pfn(...) { <...
-e1 = e2;
-return e1;
+return e2;
...> }

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/5] drivers/video/epson1355fb.c: use devm_ functions
  2012-08-03 15:40 [PATCH 0/5] use devm_ functions Damien Cassou
@ 2012-08-03 15:40 ` Damien Cassou
  2012-08-23 20:40   ` Florian Tobias Schandinat
  2012-08-03 15:40 ` [PATCH 3/5] drivers/video/jz4740_fb.c: " Damien Cassou
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Damien Cassou @ 2012-08-03 15:40 UTC (permalink / raw)
  To: Christopher Hoover
  Cc: kernel-janitors, Florian Tobias Schandinat, linux-fbdev, linux-kernel

From: Damien Cassou <damien.cassou@lifl.fr>

The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in the
probe function of a platform device and is only freed in the remove function.

Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

---
 drivers/video/epson1355fb.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/video/epson1355fb.c b/drivers/video/epson1355fb.c
index 68b9b51..246da1e 100644
--- a/drivers/video/epson1355fb.c
+++ b/drivers/video/epson1355fb.c
@@ -592,12 +592,8 @@ static int epson1355fb_remove(struct platform_device *dev)

 	if (info) {
 		fb_dealloc_cmap(&info->cmap);
-		if (info->screen_base)
-			iounmap(info->screen_base);
 		framebuffer_release(info);
 	}
-	release_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN);
-	release_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN);
 	return 0;
 }

@@ -608,15 +604,18 @@ static int __devinit epson1355fb_probe(struct platform_device *dev)
 	u8 revision;
 	int rc = 0;

-	if (!request_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN, "S1D13505 registers")) {
+	if (!devm_request_mem_region(&dev->dev, EPSON1355FB_REGS_PHYS,
+				     EPSON1355FB_REGS_LEN,
+				     "S1D13505 registers")) {
 		printk(KERN_ERR "epson1355fb: unable to reserve "
 		       "registers at 0x%0x\n", EPSON1355FB_REGS_PHYS);
 		rc = -EBUSY;
 		goto bail;
 	}

-	if (!request_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN,
-				"S1D13505 framebuffer")) {
+	if (!devm_request_mem_region(&dev->dev, EPSON1355FB_FB_PHYS,
+				     EPSON1355FB_FB_LEN,
+				     "S1D13505 framebuffer")) {
 		printk(KERN_ERR "epson1355fb: unable to reserve "
 		       "framebuffer at 0x%0x\n", EPSON1355FB_FB_PHYS);
 		rc = -EBUSY;
@@ -638,7 +637,8 @@ static int __devinit epson1355fb_probe(struct platform_device *dev)
 	}
 	info->pseudo_palette = default_par->pseudo_palette;

-	info->screen_base = ioremap(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN);
+	info->screen_base = devm_ioremap(&dev->dev, EPSON1355FB_FB_PHYS,
+					 EPSON1355FB_FB_LEN);
 	if (!info->screen_base) {
 		printk(KERN_ERR "epson1355fb: unable to map framebuffer\n");
 		rc = -ENOMEM;

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/5] drivers/video/jz4740_fb.c: use devm_ functions
  2012-08-03 15:40 [PATCH 0/5] use devm_ functions Damien Cassou
  2012-08-03 15:40 ` [PATCH 1/5] drivers/video/epson1355fb.c: " Damien Cassou
@ 2012-08-03 15:40 ` Damien Cassou
  2012-08-23 20:41   ` Florian Tobias Schandinat
  2012-08-03 15:40 ` [PATCH 2/5] drivers/video/bf54x-lq043fb.c: " Damien Cassou
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Damien Cassou @ 2012-08-03 15:40 UTC (permalink / raw)
  To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel

From: Damien Cassou <damien.cassou@lifl.fr>

The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in the
probe function of a platform device and is only freed in the remove function.

Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

---
 drivers/video/jz4740_fb.c |   22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
index de36693..7669770 100644
--- a/drivers/video/jz4740_fb.c
+++ b/drivers/video/jz4740_fb.c
@@ -659,25 +659,25 @@ static int __devinit jzfb_probe(struct platform_device *pdev)
 	jzfb->pdata = pdata;
 	jzfb->mem = mem;

-	jzfb->ldclk = clk_get(&pdev->dev, "lcd");
+	jzfb->ldclk = devm_clk_get(&pdev->dev, "lcd");
 	if (IS_ERR(jzfb->ldclk)) {
 		ret = PTR_ERR(jzfb->ldclk);
 		dev_err(&pdev->dev, "Failed to get lcd clock: %d\n", ret);
 		goto err_framebuffer_release;
 	}

-	jzfb->lpclk = clk_get(&pdev->dev, "lcd_pclk");
+	jzfb->lpclk = devm_clk_get(&pdev->dev, "lcd_pclk");
 	if (IS_ERR(jzfb->lpclk)) {
 		ret = PTR_ERR(jzfb->lpclk);
 		dev_err(&pdev->dev, "Failed to get lcd pixel clock: %d\n", ret);
-		goto err_put_ldclk;
+		goto err_framebuffer_release;
 	}

-	jzfb->base = ioremap(mem->start, resource_size(mem));
+	jzfb->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
 	if (!jzfb->base) {
 		dev_err(&pdev->dev, "Failed to ioremap register memory region\n");
 		ret = -EBUSY;
-		goto err_put_lpclk;
+		goto err_framebuffer_release;
 	}

 	platform_set_drvdata(pdev, jzfb);
@@ -693,7 +693,7 @@ static int __devinit jzfb_probe(struct platform_device *pdev)
 	ret = jzfb_alloc_devmem(jzfb);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to allocate video memory\n");
-		goto err_iounmap;
+		goto err_framebuffer_release;
 	}

 	fb->fix = jzfb_fix;
@@ -734,12 +734,6 @@ err_free_devmem:

 	fb_dealloc_cmap(&fb->cmap);
 	jzfb_free_devmem(jzfb);
-err_iounmap:
-	iounmap(jzfb->base);
-err_put_lpclk:
-	clk_put(jzfb->lpclk);
-err_put_ldclk:
-	clk_put(jzfb->ldclk);
 err_framebuffer_release:
 	framebuffer_release(fb);
 err_release_mem_region:
@@ -756,7 +750,6 @@ static int __devexit jzfb_remove(struct platform_device *pdev)
 	jz_gpio_bulk_free(jz_lcd_ctrl_pins, jzfb_num_ctrl_pins(jzfb));
 	jz_gpio_bulk_free(jz_lcd_data_pins, jzfb_num_data_pins(jzfb));

-	iounmap(jzfb->base);
 	release_mem_region(jzfb->mem->start, resource_size(jzfb->mem));

 	fb_dealloc_cmap(&jzfb->fb->cmap);
@@ -764,9 +757,6 @@ static int __devexit jzfb_remove(struct platform_device *pdev)

 	platform_set_drvdata(pdev, NULL);

-	clk_put(jzfb->lpclk);
-	clk_put(jzfb->ldclk);
-
 	framebuffer_release(jzfb->fb);

 	return 0;

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/5] drivers/video/bf54x-lq043fb.c: use devm_ functions
  2012-08-03 15:40 [PATCH 0/5] use devm_ functions Damien Cassou
  2012-08-03 15:40 ` [PATCH 1/5] drivers/video/epson1355fb.c: " Damien Cassou
  2012-08-03 15:40 ` [PATCH 3/5] drivers/video/jz4740_fb.c: " Damien Cassou
@ 2012-08-03 15:40 ` Damien Cassou
  2012-08-23 20:41   ` Florian Tobias Schandinat
  2012-08-03 15:40 ` [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: " Damien Cassou
  2012-08-03 15:40 ` [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: " Damien Cassou
  4 siblings, 1 reply; 18+ messages in thread
From: Damien Cassou @ 2012-08-03 15:40 UTC (permalink / raw)
  To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel

From: Damien Cassou <damien.cassou@lifl.fr>

The various devm_ functions allocate memory that is released when a driver
detaches. This patch replaces the use of kzalloc by devm_kzalloc.

Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

---
 drivers/video/bf54x-lq043fb.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
index dc2f004..47702ee 100644
--- a/drivers/video/bf54x-lq043fb.c
+++ b/drivers/video/bf54x-lq043fb.c
@@ -601,7 +601,8 @@ static int __devinit bfin_bf54x_probe(struct platform_device *pdev)

 	fbinfo->fbops = &bfin_bf54x_fb_ops;

-	fbinfo->pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
+	fbinfo->pseudo_palette = devm_kzalloc(&pdev->dev, sizeof(u32) * 16,
+					      GFP_KERNEL);
 	if (!fbinfo->pseudo_palette) {
 		printk(KERN_ERR DRIVER_NAME
 		       "Fail to allocate pseudo_palette\n");
@@ -616,7 +617,7 @@ static int __devinit bfin_bf54x_probe(struct platform_device *pdev)
 		       "Fail to allocate colormap (%d entries)\n",
 		       BFIN_LCD_NBR_PALETTE_ENTRIES);
 		ret = -EFAULT;
-		goto out5;
+		goto out4;
 	}

 	if (request_ports(info)) {
@@ -671,8 +672,6 @@ out7:
 	free_ports(info);
 out6:
 	fb_dealloc_cmap(&fbinfo->cmap);
-out5:
-	kfree(fbinfo->pseudo_palette);
 out4:
 	dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
 			  info->dma_handle);
@@ -699,7 +698,6 @@ static int __devexit bfin_bf54x_remove(struct platform_device *pdev)
 		dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
 				  info->dma_handle);

-	kfree(fbinfo->pseudo_palette);
 	fb_dealloc_cmap(&fbinfo->cmap);

 #ifndef NO_BL_SUPPORT

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: use devm_ functions
  2012-08-03 15:40 [PATCH 0/5] use devm_ functions Damien Cassou
                   ` (2 preceding siblings ...)
  2012-08-03 15:40 ` [PATCH 2/5] drivers/video/bf54x-lq043fb.c: " Damien Cassou
@ 2012-08-03 15:40 ` Damien Cassou
  2012-08-06  9:06   ` Dan Carpenter
                     ` (2 more replies)
  2012-08-03 15:40 ` [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: " Damien Cassou
  4 siblings, 3 replies; 18+ messages in thread
From: Damien Cassou @ 2012-08-03 15:40 UTC (permalink / raw)
  To: David Brown
  Cc: kernel-janitors, Daniel Walker, Bryan Huntsman,
	Florian Tobias Schandinat, linux-arm-msm, linux-fbdev,
	linux-kernel

From: Damien Cassou <damien.cassou@lifl.fr>

The various devm_ functions allocate memory that is released when a driver
detaches. This patch replaces the use of kzalloc by devm_kzalloc.

Additionally, this patch fixes a memory leak: some memory was allocated for
'panel' but not released when the subsequent call to setup_vsync fails.

Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

---
 drivers/video/msm/mddi_client_nt35399.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/video/msm/mddi_client_nt35399.c b/drivers/video/msm/mddi_client_nt35399.c
index 7fcd67e..66b314e 100644
--- a/drivers/video/msm/mddi_client_nt35399.c
+++ b/drivers/video/msm/mddi_client_nt35399.c
@@ -189,8 +189,9 @@ static int mddi_nt35399_probe(struct platform_device *pdev)

 	int ret;

-	struct panel_info *panel = kzalloc(sizeof(struct panel_info),
-					   GFP_KERNEL);
+	struct panel_info *panel = devm_kzalloc(&pdev->dev,
+						sizeof(struct panel_info),
+						GFP_KERNEL);

 	printk(KERN_DEBUG "%s: enter.\n", __func__);

@@ -233,7 +234,6 @@ static int mddi_nt35399_remove(struct platform_device *pdev)
 	struct panel_info *panel = platform_get_drvdata(pdev);

 	setup_vsync(panel, 0);
-	kfree(panel);
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: use devm_ functions
  2012-08-03 15:40 [PATCH 0/5] use devm_ functions Damien Cassou
                   ` (3 preceding siblings ...)
  2012-08-03 15:40 ` [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: " Damien Cassou
@ 2012-08-03 15:40 ` Damien Cassou
  2012-08-09 17:39   ` David Brown
  2012-08-09 17:57   ` David Brown
  4 siblings, 2 replies; 18+ messages in thread
From: Damien Cassou @ 2012-08-03 15:40 UTC (permalink / raw)
  To: David Brown
  Cc: kernel-janitors, Daniel Walker, Bryan Huntsman,
	Florian Tobias Schandinat, linux-arm-msm, linux-fbdev,
	linux-kernel

From: Damien Cassou <damien.cassou@lifl.fr>

The various devm_ functions allocate memory that is released when a driver
detaches. This patch replaces the use of kzalloc by devm_kzalloc.

Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

---
 drivers/video/msm/mddi_client_dummy.c |   12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/video/msm/mddi_client_dummy.c b/drivers/video/msm/mddi_client_dummy.c
index d2a091c..4c31325 100644
--- a/drivers/video/msm/mddi_client_dummy.c
+++ b/drivers/video/msm/mddi_client_dummy.c
@@ -51,7 +51,7 @@ static int mddi_dummy_probe(struct platform_device *pdev)
 {
 	struct msm_mddi_client_data *client_data = pdev->dev.platform_data;
 	struct panel_info *panel =
-		kzalloc(sizeof(struct panel_info), GFP_KERNEL);
+		devm_kzalloc(&pdev->dev, sizeof(struct panel_info), GFP_KERNEL);
 	int ret;
 	if (!panel)
 		return -ENOMEM;
@@ -67,18 +67,11 @@ static int mddi_dummy_probe(struct platform_device *pdev)
 				      client_data->fb_resource, 1);
 	panel->panel_data.fb_data = client_data->private_client_data;
 	panel->pdev.dev.platform_data = &panel->panel_data;
-	ret = platform_device_register(&panel->pdev);
-	if (ret) {
-		kfree(panel);
-		return ret;
-	}
-	return 0;
+	return platform_device_register(&panel->pdev);
 }

 static int mddi_dummy_remove(struct platform_device *pdev)
 {
-	struct panel_info *panel = platform_get_drvdata(pdev);
-	kfree(panel);
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: " Damien Cassou
@ 2012-08-06  9:06   ` Dan Carpenter
  2012-08-09 17:38   ` David Brown
  2012-08-23 20:42   ` Florian Tobias Schandinat
  2 siblings, 0 replies; 18+ messages in thread
From: Dan Carpenter @ 2012-08-06  9:06 UTC (permalink / raw)
  To: Damien Cassou
  Cc: David Brown, kernel-janitors, Daniel Walker, Bryan Huntsman,
	Florian Tobias Schandinat, linux-arm-msm, linux-fbdev,
	linux-kernel

On Fri, Aug 03, 2012 at 05:40:13PM +0200, Damien Cassou wrote:
> @@ -233,7 +234,6 @@ static int mddi_nt35399_remove(struct platform_device *pdev)
>  	struct panel_info *panel = platform_get_drvdata(pdev);
> 
>  	setup_vsync(panel, 0);
> -	kfree(panel);
>  	return 0;
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in

It's weird.  This patch doesn't apply for me unless I add a blank
line between the "}" and the "--".  I'm not sure if that line is
getting removed by your email client or by the kernel janitors email
list.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: " Damien Cassou
  2012-08-06  9:06   ` Dan Carpenter
@ 2012-08-09 17:38   ` David Brown
  2012-08-23 20:42   ` Florian Tobias Schandinat
  2 siblings, 0 replies; 18+ messages in thread
From: David Brown @ 2012-08-09 17:38 UTC (permalink / raw)
  To: Damien Cassou
  Cc: kernel-janitors, Daniel Walker, Bryan Huntsman,
	Florian Tobias Schandinat, linux-arm-msm, linux-fbdev,
	linux-kernel

On Fri, Aug 03, 2012 at 05:40:13PM +0200, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
> 
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch replaces the use of kzalloc by devm_kzalloc.
> 
> Additionally, this patch fixes a memory leak: some memory was allocated for
> 'panel' but not released when the subsequent call to setup_vsync fails.
> 
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

Acked-by: David Brown <davidb@codeaurora.org>

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: " Damien Cassou
@ 2012-08-09 17:39   ` David Brown
  2012-08-09 17:57   ` David Brown
  1 sibling, 0 replies; 18+ messages in thread
From: David Brown @ 2012-08-09 17:39 UTC (permalink / raw)
  To: Damien Cassou
  Cc: kernel-janitors, Daniel Walker, Bryan Huntsman,
	Florian Tobias Schandinat, linux-arm-msm, linux-fbdev,
	linux-kernel

On Fri, Aug 03, 2012 at 05:40:14PM +0200, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
> 
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch replaces the use of kzalloc by devm_kzalloc.
> 
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
> 
> ---
>  drivers/video/msm/mddi_client_dummy.c |   12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)

Acked-by: David Brown <davidb@codeaurora.org>

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: " Damien Cassou
  2012-08-09 17:39   ` David Brown
@ 2012-08-09 17:57   ` David Brown
  2012-08-28  8:42     ` Damien Cassou
  1 sibling, 1 reply; 18+ messages in thread
From: David Brown @ 2012-08-09 17:57 UTC (permalink / raw)
  To: Damien Cassou
  Cc: kernel-janitors, Daniel Walker, Bryan Huntsman,
	Florian Tobias Schandinat, linux-arm-msm, linux-fbdev,
	linux-kernel

On Fri, Aug 03, 2012 at 05:40:14PM +0200, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
> 
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch replaces the use of kzalloc by devm_kzalloc.
> 
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
> 
> ---
>  drivers/video/msm/mddi_client_dummy.c |   12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/video/msm/mddi_client_dummy.c b/drivers/video/msm/mddi_client_dummy.c
> index d2a091c..4c31325 100644
> --- a/drivers/video/msm/mddi_client_dummy.c
> +++ b/drivers/video/msm/mddi_client_dummy.c
> @@ -51,7 +51,7 @@ static int mddi_dummy_probe(struct platform_device *pdev)
>  {
>  	struct msm_mddi_client_data *client_data = pdev->dev.platform_data;
>  	struct panel_info *panel =
> -		kzalloc(sizeof(struct panel_info), GFP_KERNEL);
> +		devm_kzalloc(&pdev->dev, sizeof(struct panel_info), GFP_KERNEL);
>  	int ret;
>  	if (!panel)
>  		return -ENOMEM;
> @@ -67,18 +67,11 @@ static int mddi_dummy_probe(struct platform_device *pdev)
>  				      client_data->fb_resource, 1);
>  	panel->panel_data.fb_data = client_data->private_client_data;
>  	panel->pdev.dev.platform_data = &panel->panel_data;
> -	ret = platform_device_register(&panel->pdev);
> -	if (ret) {
> -		kfree(panel);
> -		return ret;
> -	}
> -	return 0;
> +	return platform_device_register(&panel->pdev);

Removing this block causes a warning:
kernel/drivers/video/msm/mddi_client_dummy.c: In function 'mddi_dummy_probe':
kernel/drivers/video/msm/mddi_client_dummy.c:55:6: warning: unused variable 'ret' [-Wunused-variable]

Please remove the 'int ret;' line above as well.

Thanks,
David Brown

-- 
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/5] drivers/video/epson1355fb.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 1/5] drivers/video/epson1355fb.c: " Damien Cassou
@ 2012-08-23 20:40   ` Florian Tobias Schandinat
  0 siblings, 0 replies; 18+ messages in thread
From: Florian Tobias Schandinat @ 2012-08-23 20:40 UTC (permalink / raw)
  To: Damien Cassou
  Cc: Christopher Hoover, kernel-janitors, linux-fbdev, linux-kernel

On 08/03/2012 03:40 PM, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
> 
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in the
> probe function of a platform device and is only freed in the remove function.
> 
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

Applied.


Thanks,

Florian Tobias Schandinat

> 
> ---
>  drivers/video/epson1355fb.c |   16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/video/epson1355fb.c b/drivers/video/epson1355fb.c
> index 68b9b51..246da1e 100644
> --- a/drivers/video/epson1355fb.c
> +++ b/drivers/video/epson1355fb.c
> @@ -592,12 +592,8 @@ static int epson1355fb_remove(struct platform_device *dev)
> 
>  	if (info) {
>  		fb_dealloc_cmap(&info->cmap);
> -		if (info->screen_base)
> -			iounmap(info->screen_base);
>  		framebuffer_release(info);
>  	}
> -	release_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN);
> -	release_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN);
>  	return 0;
>  }
> 
> @@ -608,15 +604,18 @@ static int __devinit epson1355fb_probe(struct platform_device *dev)
>  	u8 revision;
>  	int rc = 0;
> 
> -	if (!request_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN, "S1D13505 registers")) {
> +	if (!devm_request_mem_region(&dev->dev, EPSON1355FB_REGS_PHYS,
> +				     EPSON1355FB_REGS_LEN,
> +				     "S1D13505 registers")) {
>  		printk(KERN_ERR "epson1355fb: unable to reserve "
>  		       "registers at 0x%0x\n", EPSON1355FB_REGS_PHYS);
>  		rc = -EBUSY;
>  		goto bail;
>  	}
> 
> -	if (!request_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN,
> -				"S1D13505 framebuffer")) {
> +	if (!devm_request_mem_region(&dev->dev, EPSON1355FB_FB_PHYS,
> +				     EPSON1355FB_FB_LEN,
> +				     "S1D13505 framebuffer")) {
>  		printk(KERN_ERR "epson1355fb: unable to reserve "
>  		       "framebuffer at 0x%0x\n", EPSON1355FB_FB_PHYS);
>  		rc = -EBUSY;
> @@ -638,7 +637,8 @@ static int __devinit epson1355fb_probe(struct platform_device *dev)
>  	}
>  	info->pseudo_palette = default_par->pseudo_palette;
> 
> -	info->screen_base = ioremap(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN);
> +	info->screen_base = devm_ioremap(&dev->dev, EPSON1355FB_FB_PHYS,
> +					 EPSON1355FB_FB_LEN);
>  	if (!info->screen_base) {
>  		printk(KERN_ERR "epson1355fb: unable to map framebuffer\n");
>  		rc = -ENOMEM;
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/5] drivers/video/jz4740_fb.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 3/5] drivers/video/jz4740_fb.c: " Damien Cassou
@ 2012-08-23 20:41   ` Florian Tobias Schandinat
  2012-09-02 15:19     ` Lars-Peter Clausen
  0 siblings, 1 reply; 18+ messages in thread
From: Florian Tobias Schandinat @ 2012-08-23 20:41 UTC (permalink / raw)
  To: Damien Cassou; +Cc: kernel-janitors, linux-fbdev, linux-kernel

On 08/03/2012 03:40 PM, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
> 
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch uses these functions for data that is allocated in the
> probe function of a platform device and is only freed in the remove function.
> 
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

Applied.


Thanks,

Florian Tobias Schandinat

> 
> ---
>  drivers/video/jz4740_fb.c |   22 ++++++----------------
>  1 file changed, 6 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
> index de36693..7669770 100644
> --- a/drivers/video/jz4740_fb.c
> +++ b/drivers/video/jz4740_fb.c
> @@ -659,25 +659,25 @@ static int __devinit jzfb_probe(struct platform_device *pdev)
>  	jzfb->pdata = pdata;
>  	jzfb->mem = mem;
> 
> -	jzfb->ldclk = clk_get(&pdev->dev, "lcd");
> +	jzfb->ldclk = devm_clk_get(&pdev->dev, "lcd");
>  	if (IS_ERR(jzfb->ldclk)) {
>  		ret = PTR_ERR(jzfb->ldclk);
>  		dev_err(&pdev->dev, "Failed to get lcd clock: %d\n", ret);
>  		goto err_framebuffer_release;
>  	}
> 
> -	jzfb->lpclk = clk_get(&pdev->dev, "lcd_pclk");
> +	jzfb->lpclk = devm_clk_get(&pdev->dev, "lcd_pclk");
>  	if (IS_ERR(jzfb->lpclk)) {
>  		ret = PTR_ERR(jzfb->lpclk);
>  		dev_err(&pdev->dev, "Failed to get lcd pixel clock: %d\n", ret);
> -		goto err_put_ldclk;
> +		goto err_framebuffer_release;
>  	}
> 
> -	jzfb->base = ioremap(mem->start, resource_size(mem));
> +	jzfb->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
>  	if (!jzfb->base) {
>  		dev_err(&pdev->dev, "Failed to ioremap register memory region\n");
>  		ret = -EBUSY;
> -		goto err_put_lpclk;
> +		goto err_framebuffer_release;
>  	}
> 
>  	platform_set_drvdata(pdev, jzfb);
> @@ -693,7 +693,7 @@ static int __devinit jzfb_probe(struct platform_device *pdev)
>  	ret = jzfb_alloc_devmem(jzfb);
>  	if (ret) {
>  		dev_err(&pdev->dev, "Failed to allocate video memory\n");
> -		goto err_iounmap;
> +		goto err_framebuffer_release;
>  	}
> 
>  	fb->fix = jzfb_fix;
> @@ -734,12 +734,6 @@ err_free_devmem:
> 
>  	fb_dealloc_cmap(&fb->cmap);
>  	jzfb_free_devmem(jzfb);
> -err_iounmap:
> -	iounmap(jzfb->base);
> -err_put_lpclk:
> -	clk_put(jzfb->lpclk);
> -err_put_ldclk:
> -	clk_put(jzfb->ldclk);
>  err_framebuffer_release:
>  	framebuffer_release(fb);
>  err_release_mem_region:
> @@ -756,7 +750,6 @@ static int __devexit jzfb_remove(struct platform_device *pdev)
>  	jz_gpio_bulk_free(jz_lcd_ctrl_pins, jzfb_num_ctrl_pins(jzfb));
>  	jz_gpio_bulk_free(jz_lcd_data_pins, jzfb_num_data_pins(jzfb));
> 
> -	iounmap(jzfb->base);
>  	release_mem_region(jzfb->mem->start, resource_size(jzfb->mem));
> 
>  	fb_dealloc_cmap(&jzfb->fb->cmap);
> @@ -764,9 +757,6 @@ static int __devexit jzfb_remove(struct platform_device *pdev)
> 
>  	platform_set_drvdata(pdev, NULL);
> 
> -	clk_put(jzfb->lpclk);
> -	clk_put(jzfb->ldclk);
> -
>  	framebuffer_release(jzfb->fb);
> 
>  	return 0;
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/5] drivers/video/bf54x-lq043fb.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 2/5] drivers/video/bf54x-lq043fb.c: " Damien Cassou
@ 2012-08-23 20:41   ` Florian Tobias Schandinat
  0 siblings, 0 replies; 18+ messages in thread
From: Florian Tobias Schandinat @ 2012-08-23 20:41 UTC (permalink / raw)
  To: Damien Cassou; +Cc: kernel-janitors, linux-fbdev, linux-kernel

On 08/03/2012 03:40 PM, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
> 
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch replaces the use of kzalloc by devm_kzalloc.
> 
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

Applied.


Thanks,

Florian Tobias Schandinat

> 
> ---
>  drivers/video/bf54x-lq043fb.c |    8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
> index dc2f004..47702ee 100644
> --- a/drivers/video/bf54x-lq043fb.c
> +++ b/drivers/video/bf54x-lq043fb.c
> @@ -601,7 +601,8 @@ static int __devinit bfin_bf54x_probe(struct platform_device *pdev)
> 
>  	fbinfo->fbops = &bfin_bf54x_fb_ops;
> 
> -	fbinfo->pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
> +	fbinfo->pseudo_palette = devm_kzalloc(&pdev->dev, sizeof(u32) * 16,
> +					      GFP_KERNEL);
>  	if (!fbinfo->pseudo_palette) {
>  		printk(KERN_ERR DRIVER_NAME
>  		       "Fail to allocate pseudo_palette\n");
> @@ -616,7 +617,7 @@ static int __devinit bfin_bf54x_probe(struct platform_device *pdev)
>  		       "Fail to allocate colormap (%d entries)\n",
>  		       BFIN_LCD_NBR_PALETTE_ENTRIES);
>  		ret = -EFAULT;
> -		goto out5;
> +		goto out4;
>  	}
> 
>  	if (request_ports(info)) {
> @@ -671,8 +672,6 @@ out7:
>  	free_ports(info);
>  out6:
>  	fb_dealloc_cmap(&fbinfo->cmap);
> -out5:
> -	kfree(fbinfo->pseudo_palette);
>  out4:
>  	dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
>  			  info->dma_handle);
> @@ -699,7 +698,6 @@ static int __devexit bfin_bf54x_remove(struct platform_device *pdev)
>  		dma_free_coherent(NULL, fbinfo->fix.smem_len, info->fb_buffer,
>  				  info->dma_handle);
> 
> -	kfree(fbinfo->pseudo_palette);
>  	fb_dealloc_cmap(&fbinfo->cmap);
> 
>  #ifndef NO_BL_SUPPORT
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: use devm_ functions
  2012-08-03 15:40 ` [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: " Damien Cassou
  2012-08-06  9:06   ` Dan Carpenter
  2012-08-09 17:38   ` David Brown
@ 2012-08-23 20:42   ` Florian Tobias Schandinat
  2 siblings, 0 replies; 18+ messages in thread
From: Florian Tobias Schandinat @ 2012-08-23 20:42 UTC (permalink / raw)
  To: Damien Cassou
  Cc: David Brown, kernel-janitors, Daniel Walker, Bryan Huntsman,
	linux-arm-msm, linux-fbdev, linux-kernel

On 08/03/2012 03:40 PM, Damien Cassou wrote:
> From: Damien Cassou <damien.cassou@lifl.fr>
> 
> The various devm_ functions allocate memory that is released when a driver
> detaches. This patch replaces the use of kzalloc by devm_kzalloc.
> 
> Additionally, this patch fixes a memory leak: some memory was allocated for
> 'panel' but not released when the subsequent call to setup_vsync fails.
> 
> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>

Applied.


Thanks,

Florian Tobias Schandinat

> 
> ---
>  drivers/video/msm/mddi_client_nt35399.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/video/msm/mddi_client_nt35399.c b/drivers/video/msm/mddi_client_nt35399.c
> index 7fcd67e..66b314e 100644
> --- a/drivers/video/msm/mddi_client_nt35399.c
> +++ b/drivers/video/msm/mddi_client_nt35399.c
> @@ -189,8 +189,9 @@ static int mddi_nt35399_probe(struct platform_device *pdev)
> 
>  	int ret;
> 
> -	struct panel_info *panel = kzalloc(sizeof(struct panel_info),
> -					   GFP_KERNEL);
> +	struct panel_info *panel = devm_kzalloc(&pdev->dev,
> +						sizeof(struct panel_info),
> +						GFP_KERNEL);
> 
>  	printk(KERN_DEBUG "%s: enter.\n", __func__);
> 
> @@ -233,7 +234,6 @@ static int mddi_nt35399_remove(struct platform_device *pdev)
>  	struct panel_info *panel = platform_get_drvdata(pdev);
> 
>  	setup_vsync(panel, 0);
> -	kfree(panel);
>  	return 0;
>  }
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: use devm_ functions
  2012-08-09 17:57   ` David Brown
@ 2012-08-28  8:42     ` Damien Cassou
  0 siblings, 0 replies; 18+ messages in thread
From: Damien Cassou @ 2012-08-28  8:42 UTC (permalink / raw)
  To: David Brown
  Cc: kernel-janitors, Daniel Walker, Bryan Huntsman,
	Florian Tobias Schandinat, linux-arm-msm, linux-fbdev,
	linux-kernel

On Thu, Aug 9, 2012 at 7:57 PM, David Brown <davidb@codeaurora.org> wrote:
> Removing this block causes a warning:
> kernel/drivers/video/msm/mddi_client_dummy.c: In function 'mddi_dummy_probe':
> kernel/drivers/video/msm/mddi_client_dummy.c:55:6: warning: unused variable 'ret' [-Wunused-variable]
>
> Please remove the 'int ret;' line above as well.

Thank you for your feedback.
Please ignore this thread and patch. I've just sent a new email with
corrected patch.

-- 
Damien Cassou
http://damiencassou.seasidehosting.st

"Lambdas are relegated to relative obscurity until Java makes them
popular by not having them." James Iry

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/5] drivers/video/jz4740_fb.c: use devm_ functions
  2012-08-23 20:41   ` Florian Tobias Schandinat
@ 2012-09-02 15:19     ` Lars-Peter Clausen
  0 siblings, 0 replies; 18+ messages in thread
From: Lars-Peter Clausen @ 2012-09-02 15:19 UTC (permalink / raw)
  To: Florian Tobias Schandinat
  Cc: Damien Cassou, kernel-janitors, linux-fbdev, linux-kernel

On 08/23/2012 10:41 PM, Florian Tobias Schandinat wrote:
> On 08/03/2012 03:40 PM, Damien Cassou wrote:
>> From: Damien Cassou <damien.cassou@lifl.fr>
>>
>> The various devm_ functions allocate memory that is released when a driver
>> detaches. This patch uses these functions for data that is allocated in the
>> probe function of a platform device and is only freed in the remove function.
>>
>> Signed-off-by: Damien Cassou <damien.cassou@lifl.fr>
> 
> Applied.
> 
> 
> Thanks,
> 
> Florian Tobias Schandinat
> 
>>
>> ---
>>  drivers/video/jz4740_fb.c |   22 ++++++----------------
>>  1 file changed, 6 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
>> index de36693..7669770 100644
>> --- a/drivers/video/jz4740_fb.c
>> +++ b/drivers/video/jz4740_fb.c
>> @@ -659,25 +659,25 @@ static int __devinit jzfb_probe(struct platform_device *pdev)
>>  	jzfb->pdata = pdata;
>>  	jzfb->mem = mem;
>>
>> -	jzfb->ldclk = clk_get(&pdev->dev, "lcd");
>> +	jzfb->ldclk = devm_clk_get(&pdev->dev, "lcd");

I guess I'm a bit late, but we do not have devm_clk_get on jz4740 (yet), so
this patch breaks linking for this driver in next. I'll to to have this added
for the next release, but if I do not succeed we'll have to revert part of this
patch.

Also the driver does not include #include <linux/io.h>, since it is required
for devm_ioremap compilation is also broken. This one is easy to fix though,
will send a follow-up patch.

- Lars

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/5] use devm_ functions
@ 2012-07-31 16:39 Damien Cassou
  0 siblings, 0 replies; 18+ messages in thread
From: Damien Cassou @ 2012-07-31 16:39 UTC (permalink / raw)
  To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel

These patches introduce devm_ functions in some video drivers.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 0/5] use devm_ functions
@ 2012-07-31 13:54 Damien Cassou
  0 siblings, 0 replies; 18+ messages in thread
From: Damien Cassou @ 2012-07-31 13:54 UTC (permalink / raw)
  To: Florian Tobias Schandinat; +Cc: kernel-janitors, linux-fbdev, linux-kernel

These patches introduce devm_ functions in some video drivers.


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-09-02 15:20 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03 15:40 [PATCH 0/5] use devm_ functions Damien Cassou
2012-08-03 15:40 ` [PATCH 1/5] drivers/video/epson1355fb.c: " Damien Cassou
2012-08-23 20:40   ` Florian Tobias Schandinat
2012-08-03 15:40 ` [PATCH 3/5] drivers/video/jz4740_fb.c: " Damien Cassou
2012-08-23 20:41   ` Florian Tobias Schandinat
2012-09-02 15:19     ` Lars-Peter Clausen
2012-08-03 15:40 ` [PATCH 2/5] drivers/video/bf54x-lq043fb.c: " Damien Cassou
2012-08-23 20:41   ` Florian Tobias Schandinat
2012-08-03 15:40 ` [PATCH 5/5] drivers/video/msm/mddi_client_nt35399.c: " Damien Cassou
2012-08-06  9:06   ` Dan Carpenter
2012-08-09 17:38   ` David Brown
2012-08-23 20:42   ` Florian Tobias Schandinat
2012-08-03 15:40 ` [PATCH 4/5] drivers/video/msm/mddi_client_dummy.c: " Damien Cassou
2012-08-09 17:39   ` David Brown
2012-08-09 17:57   ` David Brown
2012-08-28  8:42     ` Damien Cassou
  -- strict thread matches above, loose matches on Subject: below --
2012-07-31 16:39 [PATCH 0/5] " Damien Cassou
2012-07-31 13:54 Damien Cassou

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).