aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorMarvin Borner2021-02-14 17:07:29 +0100
committerMarvin Borner2021-02-14 17:07:29 +0100
commit1287f9dfe987f0456e4fb0741385d5f0278ef53b (patch)
tree64d3da484a4d186a725779f20d339432d51f441a /kernel/drivers
parentbc4e62f629a392e1a4cf204665e91c57f4e619b2 (diff)
Message waiting and more!
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/ide.c6
-rw-r--r--kernel/drivers/keyboard.c5
-rw-r--r--kernel/drivers/mouse.c5
3 files changed, 7 insertions, 9 deletions
diff --git a/kernel/drivers/ide.c b/kernel/drivers/ide.c
index 8fc90c9..9be7956 100644
--- a/kernel/drivers/ide.c
+++ b/kernel/drivers/ide.c
@@ -126,7 +126,7 @@ void ata_probe(void)
if (!ide_find(bus, drive))
continue;
- struct device *dev = malloc(sizeof(*dev));
+ struct device *dev = zalloc(sizeof(*dev));
struct ata_data *data = malloc(sizeof(*data));
data->drive = (bus << 1) | drive;
@@ -144,7 +144,7 @@ void ata_probe(void)
continue;
// TODO: Check if ext2 first
- struct vfs *vfs = malloc(sizeof(*vfs));
+ struct vfs *vfs = zalloc(sizeof(*vfs));
vfs->type = VFS_EXT2;
vfs->read = ext2_read;
vfs->stat = ext2_stat;
@@ -158,6 +158,6 @@ void ata_probe(void)
void ata_install(void)
{
- ide_buf = malloc(SECTOR_SIZE);
+ ide_buf = zalloc(SECTOR_SIZE);
ata_probe();
}
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index 1652625..f22af80 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -33,8 +33,6 @@ void keyboard_handler()
// TODO: "Merge" scancode to linux keycode?
/* printf("%x %x = %x\n", scancode, state ? 0xe0 : 0, merged); */
- if (event)
- free(event);
event = malloc(sizeof(*event));
event->magic = KEYBOARD_MAGIC;
event->press = (scancode & 0x80) == 0;
@@ -68,6 +66,7 @@ s32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev)
struct event *e = stack_pop(queue);
memcpy(buf, (u8 *)e + offset, count);
+ free(e);
return count;
}
@@ -87,7 +86,7 @@ void keyboard_install(void)
irq_install_handler(1, keyboard_handler);
queue = stack_new();
- struct device *dev = malloc(sizeof(*dev));
+ struct device *dev = zalloc(sizeof(*dev));
dev->name = strdup("kbd");
dev->type = DEV_CHAR;
dev->read = keyboard_read;
diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c
index 1e7fd1a..6f329aa 100644
--- a/kernel/drivers/mouse.c
+++ b/kernel/drivers/mouse.c
@@ -35,8 +35,6 @@ void mouse_handler()
case 2:
mouse_byte[2] = (char)inb(0x60);
- if (event)
- free(event);
event = malloc(sizeof(*event));
event->magic = MOUSE_MAGIC;
event->diff_x = mouse_byte[1];
@@ -96,6 +94,7 @@ s32 mouse_read(void *buf, u32 offset, u32 count, struct device *dev)
struct event *e = stack_pop(queue);
memcpy(buf, (u8 *)e + offset, count);
+ free(e);
return count;
}
@@ -181,7 +180,7 @@ void mouse_install(void)
irq_install_handler(12, mouse_handler);
queue = stack_new();
- struct device *dev = malloc(sizeof(*dev));
+ struct device *dev = zalloc(sizeof(*dev));
dev->name = strdup("mouse");
dev->type = DEV_CHAR;
dev->read = mouse_read;