Skip to contentSkip to conversation

fbdev/xilinxfb: Fix improper casting and tighen up probe path

PATCH In review Grant Likely 2 participants 3 messages Jun 12, 2009 – Jun 15, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbdev/xilinxfb: Fix improper casting and tighen up probe path

From: Grant Likely <[email protected]>

The xilinxfb driver is improperly casting a physical address to a u32, and the probe routine isn't as straight forward as it could be. (discovered by gcc spitting out warnings on most recent change to xilinxfb driver).

This patch fixes the cast and simplifies the probe path.

---

John, can you please test and verify this fix is correct?

Thanks,
g.

 drivers/video/xilinxfb.c |   59 ++++++++++++++++++----------------------------
 1 files changed, 23 insertions(+), 36 deletions(-)
drivers/video/xilinxfb.c +23 -36
index 7a868bd..b68b331 100644
@@ -124,7 +124,6 @@ struct xilinxfb_drvdata {
 						registers */
 
 	dcr_host_t      dcr_host;
-	unsigned int    dcr_start;
 	unsigned int    dcr_len;
 
 	void		*fb_virt;	/* virt. address of the frame buffer */
@@ -325,8 +324,8 @@ static int xilinxfb_assign(struct device *dev,
 					drvdata->regs);
 	}
 	/* Put a banner in the log (for DEBUG) */
-	dev_dbg(dev, "fb: phys=%p, virt=%p, size=%x\n",
-		(void *)drvdata->fb_phys, drvdata->fb_virt, fbsize);
+	dev_dbg(dev, "fb: phys=%llx, virt=%p, size=%x\n",
+		(unsigned long long)drvdata->fb_phys, drvdata->fb_virt, fbsize);
 
 	return 0;	/* success */
 
@@ -404,9 +403,7 @@ xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)
 	u32 tft_access;
 	struct xilinxfb_platform_data pdata;
 	struct resource res;
-	int size, rc;
-	int start = 0, len = 0;
-	dcr_host_t dcr_host;
+	int size, rc, start;
 	struct xilinxfb_drvdata *drvdata;
 
 	/* Copy with the default pdata (not a ptr reference!) */
@@ -414,35 +411,39 @@ xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)
 
 	dev_dbg(&op->dev, "xilinxfb_of_probe(%p, %p)\n", op, match);
 
+	/* Allocate the driver data region */
+	drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata) {
+		dev_err(&op->dev, "Couldn't allocate device private record\n");
+		return -ENOMEM;
+	}
+
 	/*
 	 * To check whether the core is connected directly to DCR or PLB
 	 * interface and initialize the tft_access accordingly.
 	 */
 	p = (u32 *)of_get_property(op->node, "xlnx,dcr-splb-slave-if", NULL);
-
-	if (p)
-		tft_access = *p;
-	else
-		tft_access = 0;		/* For backward compatibility */
+	tft_access = p ? *p : 0;
 
 	/*
 	 * Fill the resource structure if its direct PLB interface
 	 * otherwise fill the dcr_host structure.
 	 */
 	if (tft_access) {
+		drvdata->flags |= PLB_ACCESS_FLAG;
 		rc = of_address_to_resource(op->node, 0, &res);
 		if (rc) {
 			dev_err(&op->dev, "invalid address\n");
-			return -ENODEV;
+			goto err;
 		}
-
 	} else {
+		res.start = 0;
 		start = dcr_resource_start(op->node, 0);
-		len = dcr_resource_len(op->node, 0);
-		dcr_host = dcr_map(op->node, start, len);
-		if (!DCR_MAP_OK(dcr_host)) {
-			dev_err(&op->dev, "invalid address\n");
-			return -ENODEV;
+		drvdata->dcr_len = dcr_resource_len(op->node, 0);
+		drvdata->dcr_host = dcr_map(op->node, start, drvdata->len);
+		if (!DCR_MAP_OK(drvdata->dcr_host)) {
+			dev_err(&op->dev, "invalid DCR address\n");
+			goto err;
 		}
 	}
 
@@ -467,26 +468,12 @@ xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)
 	if (of_find_property(op->node, "rotate-display", NULL))
 		pdata.rotate_screen = 1;
 
-	/* Allocate the driver data region */
-	drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
-	if (!drvdata) {
-		dev_err(&op->dev, "Couldn't allocate device private record\n");
-		return -ENOMEM;
-	}
 	dev_set_drvdata(&op->dev, drvdata);
+	return xilinxfb_assign(&op->dev, drvdata, res.start, &pdata);
 
-	if (tft_access)
-		drvdata->flags |= PLB_ACCESS_FLAG;
-
-	/* Arguments are passed based on the interface */
-	if (drvdata->flags & PLB_ACCESS_FLAG) {
-		return xilinxfb_assign(&op->dev, drvdata, res.start, &pdata);
-	} else {
-		drvdata->dcr_start = start;
-		drvdata->dcr_len = len;
-		drvdata->dcr_host = dcr_host;
-		return xilinxfb_assign(&op->dev, drvdata, 0, &pdata);
-	}
+ err:
+	kfree(drvdata);
+	return -ENODEV;
 }
 
 static int __devexit xilinxfb_of_remove(struct of_device *op)
#1 lore raw
Quoted 4 lines

-----Original Message-----
From: Grant Likely [mailto:[email protected]]
Sent: Friday, June 12, 2009 11:57 AM
To: [email protected]; [email protected];

[email protected]; John Linn

Quoted 1 line

Subject: [PATCH] fbdev/xilinxfb: Fix improper casting and tighen up

probe path

Quoted 11 lines

=

From: Grant Likely <[email protected]>
=

The xilinxfb driver is improperly casting a physical address to a u32, and the probe routine isn't as straight forward as it could be. (discovered by gcc spitting out warnings on most recent change to xilinxfb driver).
=

Quoted 8 lines

This patch fixes the cast and simplifies the probe path. =

---
=

John, can you please test and verify this fix is correct?

I will try to test it today.

-- John

Quoted 7 lines

=

Thanks,
g.
=

 drivers/video/xilinxfb.c |   59

++++++++++++++++++----------------------------

Quoted 18 lines
 1 files changed, 23 insertions(+), 36 deletions(-)

=

=

drivers/video/xilinxfb.c +0 -0
index 7a868bd..b68b331 100644
@@ -124,7 +124,6 @@ struct xilinxfb_drvdata {
 						registers */

=

drivers/video/xilinxfb.c +0 -1
 	dcr_host_t      dcr_host;
-	unsigned int    dcr_start;
 	unsigned int    dcr_len;

=

Quoted 1 line

void *fb_virt; /* virt. address of the frame

buffer */

drivers/video/xilinxfb.c static int xilinxfb_assign(struct device *dev, · line 328

Quoted 8 lines
drivers/video/xilinxfb.c +2 -2
@@ -325,8 +324,8 @@ static int xilinxfb_assign(struct device *dev,
 					drvdata->regs);
 	}
 	/* Put a banner in the log (for DEBUG) */
-	dev_dbg(dev, "fb: phys=3D%p, virt=3D%p, size=3D%x\n",
-		(void *)drvdata->fb_phys, drvdata->fb_virt, fbsize);
+	dev_dbg(dev, "fb: phys=3D%llx, virt=3D%p, size=3D%x\n",
+		(unsigned long long)drvdata->fb_phys, drvdata->fb_virt,

fbsize);

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const

Quoted 6 lines

=

return 0; /* success */
=

drivers/video/xilinxfb.c +0 -0
@@ -404,9 +403,7 @@ xilinxfb_of_probe(struct of_device *op, const

struct of_device_id *match)

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const

Quoted 12 lines
drivers/video/xilinxfb.c +1 -3
 	u32 tft_access;
 	struct xilinxfb_platform_data pdata;
 	struct resource res;
-	int size, rc;
-	int start =3D 0, len =3D 0;
-	dcr_host_t dcr_host;
+	int size, rc, start;
 	struct xilinxfb_drvdata *drvdata;

=

drivers/video/xilinxfb.c +0 -0
 	/* Copy with the default pdata (not a ptr reference!) */
@@ -414,35 +411,39 @@ xilinxfb_of_probe(struct of_device *op, const

struct of_device_id *match)

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)

Quoted 9 lines

=

dev_dbg(&op->dev, "xilinxfb_of_probe(%p, %p)\n", op, match);
=

drivers/video/xilinxfb.c +4 -0
+	/* Allocate the driver data region */
+	drvdata =3D kzalloc(sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata) {
+		dev_err(&op->dev, "Couldn't allocate device private

record\n");

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)

Quoted 8 lines
drivers/video/xilinxfb.c +3 -0
+		return -ENOMEM;
+	}
+
 	/*
 	 * To check whether the core is connected directly to DCR or PLB
 	 * interface and initialize the tft_access accordingly.
 	 */
 	p =3D (u32 *)of_get_property(op->node, "xlnx,dcr-splb-slave-if",

NULL);

Quoted 21 lines
drivers/video/xilinxfb.c +1 -5
-
-	if (p)
-		tft_access =3D *p;
-	else
-		tft_access =3D 0;		/* For backward compatibility */
+	tft_access =3D p ? *p : 0;

=

drivers/video/xilinxfb.c +2 -2
 	/*
 	 * Fill the resource structure if its direct PLB interface
 	 * otherwise fill the dcr_host structure.
 	 */
 	if (tft_access) {
+		drvdata->flags |=3D PLB_ACCESS_FLAG;
 		rc =3D of_address_to_resource(op->node, 0, &res);
 		if (rc) {
 			dev_err(&op->dev, "invalid address\n");
-			return -ENODEV;
+			goto err;
 		}
-

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)

Quoted 10 lines
drivers/video/xilinxfb.c +3 -5
 	} else {
+		res.start =3D 0;
 		start =3D dcr_resource_start(op->node, 0);
-		len =3D dcr_resource_len(op->node, 0);
-		dcr_host =3D dcr_map(op->node, start, len);
-		if (!DCR_MAP_OK(dcr_host)) {
-			dev_err(&op->dev, "invalid address\n");
-			return -ENODEV;
+		drvdata->dcr_len =3D dcr_resource_len(op->node, 0);
+		drvdata->dcr_host =3D dcr_map(op->node, start,

drvdata->len);

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const

Quoted 8 lines
drivers/video/xilinxfb.c +3 -0
+		if (!DCR_MAP_OK(drvdata->dcr_host)) {
+			dev_err(&op->dev, "invalid DCR address\n");
+			goto err;
 		}
 	}

=

drivers/video/xilinxfb.c +0 -0
@@ -467,26 +468,12 @@ xilinxfb_of_probe(struct of_device *op, const

struct of_device_id *match)

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)

Quoted 8 lines
drivers/video/xilinxfb.c +0 -0
 	if (of_find_property(op->node, "rotate-display", NULL))
 		pdata.rotate_screen =3D 1;

=

drivers/video/xilinxfb.c +0 -4
-	/* Allocate the driver data region */
-	drvdata =3D kzalloc(sizeof(*drvdata), GFP_KERNEL);
-	if (!drvdata) {
-		dev_err(&op->dev, "Couldn't allocate device private

record\n");

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match)

Quoted 12 lines
drivers/video/xilinxfb.c +1 -2
-		return -ENOMEM;
-	}
 	dev_set_drvdata(&op->dev, drvdata);
+	return xilinxfb_assign(&op->dev, drvdata, res.start, &pdata);

=

drivers/video/xilinxfb.c +0 -6
-	if (tft_access)
-		drvdata->flags |=3D PLB_ACCESS_FLAG;
-
-	/* Arguments are passed based on the interface */
-	if (drvdata->flags & PLB_ACCESS_FLAG) {
-		return xilinxfb_assign(&op->dev, drvdata, res.start,

&pdata);

Quoted 12 lines
drivers/video/xilinxfb.c +3 -6
-	} else {
-		drvdata->dcr_start =3D start;
-		drvdata->dcr_len =3D len;
-		drvdata->dcr_host =3D dcr_host;
-		return xilinxfb_assign(&op->dev, drvdata, 0, &pdata);
-	}
+ err:
+	kfree(drvdata);
+	return -ENODEV;
 }

=

Quoted 2 lines

static int __devexit xilinxfb_of_remove(struct of_device *op)
=

This email and any attachments are intended for the sole use of the named r= ecipient(s) and contain(s) confidential information that may be proprietary= , privileged or copyrighted under applicable law. If you are not the intend= ed recipient, do not read, copy, or forward this email message or any attac= hments. Delete this email message and any attachments immediately.

#2 lore raw
In reply to Grant Likely
Quoted 4 lines

-----Original Message-----
From: Grant Likely [mailto:[email protected]]
Sent: Friday, June 12, 2009 11:57 AM
To: [email protected]; [email protected];

[email protected]; John Linn

Quoted 1 line

Subject: [PATCH] fbdev/xilinxfb: Fix improper casting and tighen up

probe path

Quoted 11 lines

=

From: Grant Likely <[email protected]>
=

The xilinxfb driver is improperly casting a physical address to a u32, and the probe routine isn't as straight forward as it could be. (discovered by gcc spitting out warnings on most recent change to xilinxfb driver).
=

Quoted 8 lines

This patch fixes the cast and simplifies the probe path. =

---
=

John, can you please test and verify this fix is correct?

After a small fix to get it to compile, I did some quick testing with DCR and without and
it's working fine on the ML507.

-- John

Here's the small change to get it to compile.

drivers/video/xilinxfb.c +0 -0
index e3d2992..596157c 100644
@@ -441,7 +441,7 @@ xilinxfb_of_probe(struct of_device *op, const struct

of_device_id *match)
res.start =3D 0;
start =3D dcr_resource_start(op->node, 0); drvdata->dcr_len =3D dcr_resource_len(op->node, 0);
- drvdata->dcr_host =3D dcr_map(op->node, start,
drvdata->len);
+ drvdata->dcr_host =3D dcr_map(op->node, start,
drvdata->dcr_len);
if (!DCR_MAP_OK(drvdata->dcr_host)) {
dev_err(&op->dev, "invalid DCR address\n"); goto err;
--

Quoted 7 lines

=

Thanks,
g.
=

 drivers/video/xilinxfb.c |   59

++++++++++++++++++----------------------------

Quoted 18 lines
 1 files changed, 23 insertions(+), 36 deletions(-)

=

=

drivers/video/xilinxfb.c +0 -0
index 7a868bd..b68b331 100644
@@ -124,7 +124,6 @@ struct xilinxfb_drvdata {
 						registers */

=

drivers/video/xilinxfb.c +0 -1
 	dcr_host_t      dcr_host;
-	unsigned int    dcr_start;
 	unsigned int    dcr_len;

=

Quoted 1 line

void *fb_virt; /* virt. address of the frame

buffer */

drivers/video/xilinxfb.c static int xilinxfb_assign(struct device *dev, · line 328

Quoted 8 lines
drivers/video/xilinxfb.c +2 -2
@@ -325,8 +324,8 @@ static int xilinxfb_assign(struct device *dev,
 					drvdata->regs);
 	}
 	/* Put a banner in the log (for DEBUG) */
-	dev_dbg(dev, "fb: phys=3D%p, virt=3D%p, size=3D%x\n",
-		(void *)drvdata->fb_phys, drvdata->fb_virt, fbsize);
+	dev_dbg(dev, "fb: phys=3D%llx, virt=3D%p, size=3D%x\n",
+		(unsigned long long)drvdata->fb_phys, drvdata->fb_virt,

fbsize);

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const

Quoted 6 lines

=

return 0; /* success */
=

drivers/video/xilinxfb.c +0 -0
@@ -404,9 +403,7 @@ xilinxfb_of_probe(struct of_device *op, const

struct of_device_id *match)

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const

Quoted 12 lines
drivers/video/xilinxfb.c +1 -3
 	u32 tft_access;
 	struct xilinxfb_platform_data pdata;
 	struct resource res;
-	int size, rc;
-	int start =3D 0, len =3D 0;
-	dcr_host_t dcr_host;
+	int size, rc, start;
 	struct xilinxfb_drvdata *drvdata;

=

drivers/video/xilinxfb.c +0 -0
 	/* Copy with the default pdata (not a ptr reference!) */
@@ -414,35 +411,39 @@ xilinxfb_of_probe(struct of_device *op, const

struct of_device_id *match)

drivers/video/xilinxfb.c

Quoted 9 lines

=

dev_dbg(&op->dev, "xilinxfb_of_probe(%p, %p)\n", op, match);
=

drivers/video/xilinxfb.c +4 -0
+	/* Allocate the driver data region */
+	drvdata =3D kzalloc(sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata) {
+		dev_err(&op->dev, "Couldn't allocate device private

record\n");

drivers/video/xilinxfb.c

Quoted 8 lines
drivers/video/xilinxfb.c +3 -0
+		return -ENOMEM;
+	}
+
 	/*
 	 * To check whether the core is connected directly to DCR or PLB
 	 * interface and initialize the tft_access accordingly.
 	 */
 	p =3D (u32 *)of_get_property(op->node, "xlnx,dcr-splb-slave-if",

NULL);

Quoted 21 lines
drivers/video/xilinxfb.c +1 -5
-
-	if (p)
-		tft_access =3D *p;
-	else
-		tft_access =3D 0;		/* For backward compatibility */
+	tft_access =3D p ? *p : 0;

=

drivers/video/xilinxfb.c +2 -2
 	/*
 	 * Fill the resource structure if its direct PLB interface
 	 * otherwise fill the dcr_host structure.
 	 */
 	if (tft_access) {
+		drvdata->flags |=3D PLB_ACCESS_FLAG;
 		rc =3D of_address_to_resource(op->node, 0, &res);
 		if (rc) {
 			dev_err(&op->dev, "invalid address\n");
-			return -ENODEV;
+			goto err;
 		}
-

drivers/video/xilinxfb.c

Quoted 10 lines
drivers/video/xilinxfb.c +3 -5
 	} else {
+		res.start =3D 0;
 		start =3D dcr_resource_start(op->node, 0);
-		len =3D dcr_resource_len(op->node, 0);
-		dcr_host =3D dcr_map(op->node, start, len);
-		if (!DCR_MAP_OK(dcr_host)) {
-			dev_err(&op->dev, "invalid address\n");
-			return -ENODEV;
+		drvdata->dcr_len =3D dcr_resource_len(op->node, 0);
+		drvdata->dcr_host =3D dcr_map(op->node, start,

drvdata->len);

drivers/video/xilinxfb.c xilinxfb_of_probe(struct of_device *op, const

Quoted 8 lines
drivers/video/xilinxfb.c +3 -0
+		if (!DCR_MAP_OK(drvdata->dcr_host)) {
+			dev_err(&op->dev, "invalid DCR address\n");
+			goto err;
 		}
 	}

=

drivers/video/xilinxfb.c +0 -0
@@ -467,26 +468,12 @@ xilinxfb_of_probe(struct of_device *op, const

struct of_device_id *match)

drivers/video/xilinxfb.c

Quoted 8 lines
drivers/video/xilinxfb.c +0 -0
 	if (of_find_property(op->node, "rotate-display", NULL))
 		pdata.rotate_screen =3D 1;

=

drivers/video/xilinxfb.c +0 -4
-	/* Allocate the driver data region */
-	drvdata =3D kzalloc(sizeof(*drvdata), GFP_KERNEL);
-	if (!drvdata) {
-		dev_err(&op->dev, "Couldn't allocate device private

record\n");

drivers/video/xilinxfb.c

Quoted 12 lines
drivers/video/xilinxfb.c +1 -2
-		return -ENOMEM;
-	}
 	dev_set_drvdata(&op->dev, drvdata);
+	return xilinxfb_assign(&op->dev, drvdata, res.start, &pdata);

=

drivers/video/xilinxfb.c +0 -6
-	if (tft_access)
-		drvdata->flags |=3D PLB_ACCESS_FLAG;
-
-	/* Arguments are passed based on the interface */
-	if (drvdata->flags & PLB_ACCESS_FLAG) {
-		return xilinxfb_assign(&op->dev, drvdata, res.start,

&pdata);

Quoted 12 lines
drivers/video/xilinxfb.c +3 -6
-	} else {
-		drvdata->dcr_start =3D start;
-		drvdata->dcr_len =3D len;
-		drvdata->dcr_host =3D dcr_host;
-		return xilinxfb_assign(&op->dev, drvdata, 0, &pdata);
-	}
+ err:
+	kfree(drvdata);
+	return -ENODEV;
 }

=

Quoted 2 lines

static int __devexit xilinxfb_of_remove(struct of_device *op)
=

This email and any attachments are intended for the sole use of the named r= ecipient(s) and contain(s) confidential information that may be proprietary= , privileged or copyrighted under applicable law. If you are not the intend= ed recipient, do not read, copy, or forward this email message or any attac= hments. Delete this email message and any attachments immediately.