Commit c13cbf3b authored by Joern Engel's avatar Joern Engel Committed by Thomas Gleixner

[MTD] mtdram: Quick cleanup of the driver:

- Lindent
- Removal of slram/phram functionality
- Removal of most #ifdefs
Signed-off-by: default avatarJoern Engel <joern@wohnheim.fh-wedel.de>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 7d200960
/* /*
* mtdram - a test mtd device * mtdram - a test mtd device
* $Id: mtdram.c,v 1.35 2005/01/05 18:05:12 dwmw2 Exp $ * $Id: mtdram.c,v 1.37 2005/04/21 03:42:11 joern Exp $
* Author: Alexander Larsson <alex@cendio.se> * Author: Alexander Larsson <alex@cendio.se>
* *
* Copyright (c) 1999 Alexander Larsson <alex@cendio.se> * Copyright (c) 1999 Alexander Larsson <alex@cendio.se>
* Copyright (c) 2005 Joern Engel <joern@wh.fh-wedel.de>
* *
* This code is GPL * This code is GPL
* *
...@@ -18,41 +19,25 @@ ...@@ -18,41 +19,25 @@
#include <linux/mtd/compatmac.h> #include <linux/mtd/compatmac.h>
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#ifndef CONFIG_MTDRAM_ABS_POS
#define CONFIG_MTDRAM_ABS_POS 0
#endif
#if CONFIG_MTDRAM_ABS_POS > 0
#include <asm/io.h>
#endif
#ifdef MODULE
static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE; static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE;
static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE; static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE;
module_param(total_size,ulong,0);
MODULE_PARM_DESC(total_size, "Total device size in KiB");
module_param(erase_size,ulong,0);
MODULE_PARM_DESC(erase_size, "Device erase block size in KiB");
#define MTDRAM_TOTAL_SIZE (total_size * 1024) #define MTDRAM_TOTAL_SIZE (total_size * 1024)
#define MTDRAM_ERASE_SIZE (erase_size * 1024) #define MTDRAM_ERASE_SIZE (erase_size * 1024)
#else
#define MTDRAM_TOTAL_SIZE (CONFIG_MTDRAM_TOTAL_SIZE * 1024)
#define MTDRAM_ERASE_SIZE (CONFIG_MTDRAM_ERASE_SIZE * 1024)
#endif
#ifdef MODULE
module_param(total_size, ulong, 0);
MODULE_PARM_DESC(total_size, "Total device size in KiB");
module_param(erase_size, ulong, 0);
MODULE_PARM_DESC(erase_size, "Device erase block size in KiB");
#endif
// We could store these in the mtd structure, but we only support 1 device.. // We could store these in the mtd structure, but we only support 1 device..
static struct mtd_info *mtd_info; static struct mtd_info *mtd_info;
static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
static int
ram_erase(struct mtd_info *mtd, struct erase_info *instr)
{ {
DEBUG(MTD_DEBUG_LEVEL2, "ram_erase(pos:%ld, len:%ld)\n", (long)instr->addr, (long)instr->len); if (instr->addr + instr->len > mtd->size)
if (instr->addr + instr->len > mtd->size) {
DEBUG(MTD_DEBUG_LEVEL1, "ram_erase() out of bounds (%ld > %ld)\n", (long)(instr->addr + instr->len), (long)mtd->size);
return -EINVAL; return -EINVAL;
}
memset((char *)mtd->priv + instr->addr, 0xff, instr->len); memset((char *)mtd->priv + instr->addr, 0xff, instr->len);
...@@ -62,7 +47,8 @@ ram_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -62,7 +47,8 @@ ram_erase(struct mtd_info *mtd, struct erase_info *instr)
return 0; return 0;
} }
static int ram_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf) static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char **mtdbuf)
{ {
if (from + len > mtd->size) if (from + len > mtd->size)
return -EINVAL; return -EINVAL;
...@@ -72,39 +58,32 @@ static int ram_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *ret ...@@ -72,39 +58,32 @@ static int ram_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *ret
return 0; return 0;
} }
static void ram_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, static void ram_unpoint(struct mtd_info *mtd, u_char * addr, loff_t from,
size_t len) size_t len)
{ {
DEBUG(MTD_DEBUG_LEVEL2, "ram_unpoint\n");
} }
static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char *buf) size_t *retlen, u_char *buf)
{ {
DEBUG(MTD_DEBUG_LEVEL2, "ram_read(pos:%ld, len:%ld)\n", (long)from, (long)len); if (from + len > mtd->size)
if (from + len > mtd->size) {
DEBUG(MTD_DEBUG_LEVEL1, "ram_read() out of bounds (%ld > %ld)\n", (long)(from + len), (long)mtd->size);
return -EINVAL; return -EINVAL;
}
memcpy(buf, mtd->priv + from, len); memcpy(buf, mtd->priv + from, len);
*retlen=len; *retlen = len;
return 0; return 0;
} }
static int ram_write(struct mtd_info *mtd, loff_t to, size_t len, static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, const u_char *buf) size_t *retlen, const u_char *buf)
{ {
DEBUG(MTD_DEBUG_LEVEL2, "ram_write(pos:%ld, len:%ld)\n", (long)to, (long)len); if (to + len > mtd->size)
if (to + len > mtd->size) {
DEBUG(MTD_DEBUG_LEVEL1, "ram_write() out of bounds (%ld > %ld)\n", (long)(to + len), (long)mtd->size);
return -EINVAL; return -EINVAL;
}
memcpy ((char *)mtd->priv + to, buf, len); memcpy((char *)mtd->priv + to, buf, len);
*retlen=len; *retlen = len;
return 0; return 0;
} }
...@@ -112,14 +91,8 @@ static void __exit cleanup_mtdram(void) ...@@ -112,14 +91,8 @@ static void __exit cleanup_mtdram(void)
{ {
if (mtd_info) { if (mtd_info) {
del_mtd_device(mtd_info); del_mtd_device(mtd_info);
#if CONFIG_MTDRAM_TOTAL_SIZE > 0
if (mtd_info->priv) if (mtd_info->priv)
#if CONFIG_MTDRAM_ABS_POS > 0
iounmap(mtd_info->priv);
#else
vfree(mtd_info->priv); vfree(mtd_info->priv);
#endif
#endif
kfree(mtd_info); kfree(mtd_info);
} }
} }
...@@ -151,45 +124,14 @@ int mtdram_init_device(struct mtd_info *mtd, void *mapped_address, ...@@ -151,45 +124,14 @@ int mtdram_init_device(struct mtd_info *mtd, void *mapped_address,
return 0; return 0;
} }
#if CONFIG_MTDRAM_TOTAL_SIZE > 0
#if CONFIG_MTDRAM_ABS_POS > 0
static int __init init_mtdram(void) static int __init init_mtdram(void)
{ {
void *addr; void *addr;
int err; int err;
/* Allocate some memory */
mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
if (!mtd_info)
return -ENOMEM;
addr = ioremap(CONFIG_MTDRAM_ABS_POS, MTDRAM_TOTAL_SIZE); if (!total_size)
if (!addr) { return -EINVAL;
DEBUG(MTD_DEBUG_LEVEL1,
"Failed to ioremap) memory region of size %ld at ABS_POS:%ld\n",
(long)MTDRAM_TOTAL_SIZE, (long)CONFIG_MTDRAM_ABS_POS);
kfree(mtd_info);
mtd_info = NULL;
return -ENOMEM;
}
err = mtdram_init_device(mtd_info, addr,
MTDRAM_TOTAL_SIZE, "mtdram test device");
if (err)
{
iounmap(addr);
kfree(mtd_info);
mtd_info = NULL;
return err;
}
memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
return err;
}
#else /* CONFIG_MTDRAM_ABS_POS > 0 */
static int __init init_mtdram(void)
{
void *addr;
int err;
/* Allocate some memory */ /* Allocate some memory */
mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
if (!mtd_info) if (!mtd_info)
...@@ -197,17 +139,12 @@ static int __init init_mtdram(void) ...@@ -197,17 +139,12 @@ static int __init init_mtdram(void)
addr = vmalloc(MTDRAM_TOTAL_SIZE); addr = vmalloc(MTDRAM_TOTAL_SIZE);
if (!addr) { if (!addr) {
DEBUG(MTD_DEBUG_LEVEL1,
"Failed to vmalloc memory region of size %ld\n",
(long)MTDRAM_TOTAL_SIZE);
kfree(mtd_info); kfree(mtd_info);
mtd_info = NULL; mtd_info = NULL;
return -ENOMEM; return -ENOMEM;
} }
err = mtdram_init_device(mtd_info, addr, err = mtdram_init_device(mtd_info, addr, MTDRAM_TOTAL_SIZE, "mtdram test device");
MTDRAM_TOTAL_SIZE, "mtdram test device"); if (err) {
if (err)
{
vfree(addr); vfree(addr);
kfree(mtd_info); kfree(mtd_info);
mtd_info = NULL; mtd_info = NULL;
...@@ -216,15 +153,6 @@ static int __init init_mtdram(void) ...@@ -216,15 +153,6 @@ static int __init init_mtdram(void)
memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE); memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
return err; return err;
} }
#endif /* !(CONFIG_MTDRAM_ABS_POS > 0) */
#else /* CONFIG_MTDRAM_TOTAL_SIZE > 0 */
static int __init init_mtdram(void)
{
return 0;
}
#endif /* !(CONFIG_MTDRAM_TOTAL_SIZE > 0) */
module_init(init_mtdram); module_init(init_mtdram);
module_exit(cleanup_mtdram); module_exit(cleanup_mtdram);
...@@ -232,4 +160,3 @@ module_exit(cleanup_mtdram); ...@@ -232,4 +160,3 @@ module_exit(cleanup_mtdram);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("Alexander Larsson <alexl@redhat.com>"); MODULE_AUTHOR("Alexander Larsson <alexl@redhat.com>");
MODULE_DESCRIPTION("Simulated MTD driver for testing"); MODULE_DESCRIPTION("Simulated MTD driver for testing");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment