Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 195864
b: refs/heads/master
c: f1332ba
h: refs/heads/master
v: v3
  • Loading branch information
Ben Hutchings authored and David Woodhouse committed Feb 25, 2010
1 parent a91f612 commit 97aca26
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0040476b0efa99ad0d4ffb81d8e882095420d288
refs/heads/master: f1332ba2f23800bb5d52457ac150c568dfb1f3bf
10 changes: 5 additions & 5 deletions trunk/drivers/mtd/mtd_blkdevs.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ static struct mtd_notifier blktrans_notifier = {

int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
{
int ret, i;
struct mtd_info *mtd;
int ret;

/* Register the notifier if/when the first device type is
registered, to prevent the link/init ordering from fucking
Expand Down Expand Up @@ -389,10 +390,9 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
INIT_LIST_HEAD(&tr->devs);
list_add(&tr->list, &blktrans_majors);

for (i=0; i<MAX_MTD_DEVICES; i++) {
if (mtd_table[i] && mtd_table[i]->type != MTD_ABSENT)
tr->add_mtd(tr, mtd_table[i]);
}
mtd_for_each_device(mtd)
if (mtd->type != MTD_ABSENT)
tr->add_mtd(tr, mtd);

mutex_unlock(&mtd_table_mutex);

Expand Down
54 changes: 25 additions & 29 deletions trunk/drivers/mtd/mtdcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,16 @@ int del_mtd_device (struct mtd_info *mtd)

void register_mtd_user (struct mtd_notifier *new)
{
int i;
struct mtd_info *mtd;

mutex_lock(&mtd_table_mutex);

list_add(&new->list, &mtd_notifiers);

__module_get(THIS_MODULE);

for (i=0; i< MAX_MTD_DEVICES; i++)
if (mtd_table[i])
new->add(mtd_table[i]);
mtd_for_each_device(mtd)
new->add(mtd);

mutex_unlock(&mtd_table_mutex);
}
Expand All @@ -408,15 +407,14 @@ void register_mtd_user (struct mtd_notifier *new)

int unregister_mtd_user (struct mtd_notifier *old)
{
int i;
struct mtd_info *mtd;

mutex_lock(&mtd_table_mutex);

module_put(THIS_MODULE);

for (i=0; i< MAX_MTD_DEVICES; i++)
if (mtd_table[i])
old->remove(mtd_table[i]);
mtd_for_each_device(mtd)
old->remove(mtd);

list_del(&old->list);
mutex_unlock(&mtd_table_mutex);
Expand All @@ -438,15 +436,18 @@ int unregister_mtd_user (struct mtd_notifier *old)

struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
{
struct mtd_info *ret = NULL;
int i, err = -ENODEV;
struct mtd_info *ret = NULL, *other;
int err = -ENODEV;

mutex_lock(&mtd_table_mutex);

if (num == -1) {
for (i=0; i< MAX_MTD_DEVICES; i++)
if (mtd_table[i] == mtd)
ret = mtd_table[i];
mtd_for_each_device(other) {
if (other == mtd) {
ret = mtd;
break;
}
}
} else if (num >= 0 && num < MAX_MTD_DEVICES) {
ret = mtd_table[num];
if (mtd && mtd != ret)
Expand Down Expand Up @@ -487,14 +488,14 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)

struct mtd_info *get_mtd_device_nm(const char *name)
{
int i, err = -ENODEV;
struct mtd_info *mtd = NULL;
int err = -ENODEV;
struct mtd_info *mtd = NULL, *other;

mutex_lock(&mtd_table_mutex);

for (i = 0; i < MAX_MTD_DEVICES; i++) {
if (mtd_table[i] && !strcmp(name, mtd_table[i]->name)) {
mtd = mtd_table[i];
mtd_for_each_device(other) {
if (!strcmp(name, other->name)) {
mtd = other;
break;
}
}
Expand Down Expand Up @@ -581,30 +582,25 @@ EXPORT_SYMBOL_GPL(default_mtd_writev);

static struct proc_dir_entry *proc_mtd;

static inline int mtd_proc_info (char *buf, int i)
static inline int mtd_proc_info(char *buf, struct mtd_info *this)
{
struct mtd_info *this = mtd_table[i];

if (!this)
return 0;

return sprintf(buf, "mtd%d: %8.8llx %8.8x \"%s\"\n", i,
return sprintf(buf, "mtd%d: %8.8llx %8.8x \"%s\"\n", this->index,
(unsigned long long)this->size,
this->erasesize, this->name);
}

static int mtd_read_proc (char *page, char **start, off_t off, int count,
int *eof, void *data_unused)
{
int len, l, i;
struct mtd_info *mtd;
int len, l;
off_t begin = 0;

mutex_lock(&mtd_table_mutex);

len = sprintf(page, "dev: size erasesize name\n");
for (i=0; i< MAX_MTD_DEVICES; i++) {

l = mtd_proc_info(page + len, i);
mtd_for_each_device(mtd) {
l = mtd_proc_info(page + len, mtd);
len += l;
if (len+begin > off+count)
goto done;
Expand Down
15 changes: 15 additions & 0 deletions trunk/drivers/mtd/mtdcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,18 @@

extern struct mutex mtd_table_mutex;
extern struct mtd_info *mtd_table[MAX_MTD_DEVICES];

static inline struct mtd_info *__mtd_next_device(int i)
{
while (i < MAX_MTD_DEVICES) {
if (mtd_table[i])
return mtd_table[i];
i++;
}
return NULL;
}

#define mtd_for_each_device(mtd) \
for ((mtd) = __mtd_next_device(0); \
(mtd) != NULL; \
(mtd) = __mtd_next_device(mtd->index + 1))

0 comments on commit 97aca26

Please sign in to comment.