Skip to content

Commit e2500c6

Browse files
6by9popcornmix
authored andcommitted
char: vc_mem: Fix up compat ioctls for 64bit kernel
compat_ioctl wasn't defined, so 32bit user/64bit kernel always failed. VC_MEM_IOC_MEM_PHYS_ADDR was defined with parameter size unsigned long, so the ioctl cmd changes between sizes. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
1 parent c1d10f4 commit e2500c6

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎drivers/char/broadcom/vc_mem.c‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
148148
(void) cmd;
149149
(void) arg;
150150

151-
pr_debug("%s: called file = 0x%p\n", __func__, file);
151+
pr_debug("%s: called file = 0x%p, cmd %08x\n", __func__, file, cmd);
152152

153153
switch (cmd) {
154154
case VC_MEM_IOC_MEM_PHYS_ADDR:
@@ -167,7 +167,7 @@ vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
167167
// Get the videocore memory size first
168168
vc_mem_get_size();
169169

170-
pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
170+
pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%x\n", __func__,
171171
mm_vc_mem_size);
172172

173173
if (copy_to_user((void *) arg, &mm_vc_mem_size,
@@ -181,7 +181,7 @@ vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
181181
// Get the videocore memory base
182182
vc_mem_get_base();
183183

184-
pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
184+
pr_debug("%s: VC_MEM_IOC_MEM_BASE=%x\n", __func__,
185185
mm_vc_mem_base);
186186

187187
if (copy_to_user((void *) arg, &mm_vc_mem_base,
@@ -195,7 +195,7 @@ vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
195195
// Get the videocore memory base
196196
vc_mem_get_base();
197197

198-
pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
198+
pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%x\n", __func__,
199199
mm_vc_mem_base);
200200

201201
if (copy_to_user((void *) arg, &mm_vc_mem_base,
@@ -214,6 +214,35 @@ vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
214214
return rc;
215215
}
216216

217+
#ifdef CONFIG_COMPAT
218+
static long
219+
vc_mem_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
220+
{
221+
int rc = 0;
222+
223+
switch (cmd) {
224+
case VC_MEM_IOC_MEM_PHYS_ADDR32:
225+
pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR32=0x%p\n",
226+
__func__, (void *)mm_vc_mem_phys_addr);
227+
228+
/* This isn't correct, but will cover us for now as
229+
* VideoCore is 32bit only.
230+
*/
231+
if (copy_to_user((void *)arg, &mm_vc_mem_phys_addr,
232+
sizeof(compat_ulong_t)))
233+
rc = -EFAULT;
234+
235+
break;
236+
237+
default:
238+
rc = vc_mem_ioctl(file, cmd, arg);
239+
break;
240+
}
241+
242+
return rc;
243+
}
244+
#endif
245+
217246
/****************************************************************************
218247
*
219248
* vc_mem_mmap
@@ -259,6 +288,9 @@ static const struct file_operations vc_mem_fops = {
259288
.open = vc_mem_open,
260289
.release = vc_mem_release,
261290
.unlocked_ioctl = vc_mem_ioctl,
291+
#ifdef CONFIG_COMPAT
292+
.compat_ioctl = vc_mem_compat_ioctl,
293+
#endif
262294
.mmap = vc_mem_mmap,
263295
};
264296

‎include/linux/broadcom/vc_mem.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ extern unsigned int mm_vc_mem_size;
3232
extern int vc_mem_get_current_size( void );
3333
#endif
3434

35+
#ifdef CONFIG_COMPAT
36+
#define VC_MEM_IOC_MEM_PHYS_ADDR32 _IOR(VC_MEM_IOC_MAGIC, 0, compat_ulong_t)
37+
#endif
38+
3539
#endif /* _VC_MEM_H */

0 commit comments

Comments
 (0)