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 <noralf@tronnes.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Noralf Trønnes 2015-07-30 19:55:01 +02:00 committed by Greg Kroah-Hartman
parent bc7ac43253
commit ad6d8812aa
3 changed files with 9 additions and 10 deletions

View File

@ -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 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 fb_info *info;
struct fbtft_par *par; struct fbtft_par *par;
struct fb_ops *fbops = NULL; struct fb_ops *fbops = NULL;
struct fb_deferred_io *fbdefio = NULL; struct fb_deferred_io *fbdefio = NULL;
struct fbtft_platform_data *pdata = dev->platform_data;
u8 *vmem = NULL; u8 *vmem = NULL;
void *txbuf = NULL; void *txbuf = NULL;
void *buf = NULL; void *buf = NULL;
@ -828,7 +828,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
par = info->par; par = info->par;
par->info = info; par->info = info;
par->pdata = dev->platform_data; par->pdata = pdata;
par->debug = display->debug; par->debug = display->debug;
par->buf = buf; par->buf = buf;
spin_lock_init(&par->dirty_lock); spin_lock_init(&par->dirty_lock);
@ -1265,12 +1265,11 @@ EXPORT_SYMBOL(fbtft_init_display);
*/ */
static int fbtft_verify_gpios(struct fbtft_par *par) static int fbtft_verify_gpios(struct fbtft_par *par)
{ {
struct fbtft_platform_data *pdata; struct fbtft_platform_data *pdata = par->pdata;
int i; int i;
fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__); fbtft_par_dbg(DEBUG_VERIFY_GPIOS, par, "%s()\n", __func__);
pdata = par->info->device->platform_data;
if (pdata->display.buswidth != 9 && par->startbyte == 0 && if (pdata->display.buswidth != 9 && par->startbyte == 0 &&
par->gpio.dc < 0) { par->gpio.dc < 0) {
dev_err(par->info->device, dev_err(par->info->device,
@ -1388,10 +1387,9 @@ int fbtft_probe_common(struct fbtft_display *display,
pdata = fbtft_probe_dt(dev); pdata = fbtft_probe_dt(dev);
if (IS_ERR(pdata)) if (IS_ERR(pdata))
return PTR_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) if (!info)
return -ENOMEM; return -ENOMEM;

View File

@ -264,8 +264,9 @@ struct fbtft_par {
/* fbtft-core.c */ /* fbtft-core.c */
extern void fbtft_dbg_hex(const struct device *dev, extern void fbtft_dbg_hex(const struct device *dev,
int groupsize, void *buf, size_t len, const char *fmt, ...); int groupsize, void *buf, size_t len, const char *fmt, ...);
extern struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
struct device *dev); struct device *dev,
struct fbtft_platform_data *pdata);
extern void fbtft_framebuffer_release(struct fb_info *info); extern void fbtft_framebuffer_release(struct fb_info *info);
extern int fbtft_register_framebuffer(struct fb_info *fb_info); extern int fbtft_register_framebuffer(struct fb_info *fb_info);
extern int fbtft_unregister_framebuffer(struct fb_info *fb_info); extern int fbtft_unregister_framebuffer(struct fb_info *fb_info);

View File

@ -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, "regwidth = %d\n", regwidth);
fbtft_init_dbg(dev, "buswidth = %d\n", buswidth); 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) if (!info)
return -ENOMEM; return -ENOMEM;