[NETFILTER]: ip_tables: fix module refcount leaks in compat error paths
[hh.org.git] / drivers / video / console / softcursor.c
blob557c563e4aed2033a9ce33ea850a85b87ff35d04
1 /*
2 * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices
4 * Created 14 Nov 2002 by James Simmons
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/fb.h>
14 #include <linux/slab.h>
16 #include <asm/uaccess.h>
17 #include <asm/io.h>
19 #include "fbcon.h"
21 int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
23 unsigned int scan_align = info->pixmap.scan_align - 1;
24 unsigned int buf_align = info->pixmap.buf_align - 1;
25 unsigned int i, size, dsize, s_pitch, d_pitch;
26 struct fb_image *image;
27 u8 *dst, *src;
29 if (info->state != FBINFO_STATE_RUNNING)
30 return 0;
32 s_pitch = (cursor->image.width + 7) >> 3;
33 dsize = s_pitch * cursor->image.height;
35 src = kmalloc(dsize + sizeof(struct fb_image), GFP_ATOMIC);
36 if (!src)
37 return -ENOMEM;
39 image = (struct fb_image *) (src + dsize);
40 *image = cursor->image;
41 d_pitch = (s_pitch + scan_align) & ~scan_align;
43 size = d_pitch * image->height + buf_align;
44 size &= ~buf_align;
45 dst = fb_get_buffer_offset(info, &info->pixmap, size);
47 if (cursor->enable) {
48 switch (cursor->rop) {
49 case ROP_XOR:
50 for (i = 0; i < dsize; i++)
51 src[i] = image->data[i] ^ cursor->mask[i];
52 break;
53 case ROP_COPY:
54 default:
55 for (i = 0; i < dsize; i++)
56 src[i] = image->data[i] & cursor->mask[i];
57 break;
59 } else
60 memcpy(src, image->data, dsize);
62 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
63 image->data = dst;
64 info->fbops->fb_imageblit(info, image);
65 kfree(src);
66 return 0;
69 EXPORT_SYMBOL(soft_cursor);
71 MODULE_AUTHOR("James Simmons <jsimmons@users.sf.net>");
72 MODULE_DESCRIPTION("Generic software cursor");
73 MODULE_LICENSE("GPL");