From: Noralf Trønnes Date: Thu, 30 Jul 2015 17:55:01 +0000 (+0200) Subject: staging: fbtft: core: Don't set device platform_data X-Git-Tag: firefly_0821_release~176^2~1221^2~272 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=ad6d8812aa9574b11d5f7a0d322d3b42be24206d;p=firefly-linux-kernel-4.4.55.git staging: fbtft: core: Don't set device platform_data Pass platform_data as an argument to fbtft_framebuffer_alloc() instead of using dev->platform_data. This fixes an issue where the device comes from Device Tree and fbtft_probe_common() sets dev->platform_data to allocated memory. When the module is reloaded, dev->platform_data points to freed memory. Signed-off-by: Noralf Trønnes Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c index f04128fb0693..23392eb6799e 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -677,13 +677,13 @@ static void fbtft_merge_fbtftops(struct fbtft_ops *dst, struct fbtft_ops *src) * */ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, - struct device *dev) + struct device *dev, + struct fbtft_platform_data *pdata) { struct fb_info *info; struct fbtft_par *par; struct fb_ops *fbops = NULL; struct fb_deferred_io *fbdefio = NULL; - struct fbtft_platform_data *pdata = dev->platform_data; u8 *vmem = NULL; void *txbuf = NULL; void *buf = NULL; @@ -828,7 +828,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, par = info->par; par->info = info; - par->pdata = dev->platform_data; + par->pdata = pdata; par->debug = display->debug; par->buf = buf; spin_lock_init(&par->dirty_lock); @@ -1265,12 +1265,11 @@ EXPORT_SYMBOL(fbtft_init_display); */ static int fbtft_verify_gpios(struct fbtft_par *par) { - struct fbtft_platform_data *pdata; + struct fbtft_platform_data *pdata = par->pdata; int i; fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__); - pdata = par->info->device->platform_data; if (pdata->display.buswidth != 9 && par->startbyte == 0 && par->gpio.dc < 0) { dev_err(par->info->device, @@ -1388,10 +1387,9 @@ int fbtft_probe_common(struct fbtft_display *display, pdata = fbtft_probe_dt(dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); - dev->platform_data = pdata; } - info = fbtft_framebuffer_alloc(display, dev); + info = fbtft_framebuffer_alloc(display, dev, pdata); if (!info) return -ENOMEM; diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h index 7d817eb26eab..ab4a65818786 100644 --- a/drivers/staging/fbtft/fbtft.h +++ b/drivers/staging/fbtft/fbtft.h @@ -264,8 +264,9 @@ struct fbtft_par { /* fbtft-core.c */ extern void fbtft_dbg_hex(const struct device *dev, int groupsize, void *buf, size_t len, const char *fmt, ...); -extern struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, - struct device *dev); +struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, + struct device *dev, + struct fbtft_platform_data *pdata); extern void fbtft_framebuffer_release(struct fb_info *info); extern int fbtft_register_framebuffer(struct fb_info *fb_info); extern int fbtft_unregister_framebuffer(struct fb_info *fb_info); diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c index ce6e3ae30a2e..5b4c7124a6ee 100644 --- a/drivers/staging/fbtft/flexfb.c +++ b/drivers/staging/fbtft/flexfb.c @@ -379,7 +379,7 @@ static int flexfb_probe_common(struct spi_device *sdev, fbtft_init_dbg(dev, "regwidth = %d\n", regwidth); fbtft_init_dbg(dev, "buswidth = %d\n", buswidth); - info = fbtft_framebuffer_alloc(&flex_display, dev); + info = fbtft_framebuffer_alloc(&flex_display, dev, dev->platform_data); if (!info) return -ENOMEM;