Skip to content

Commit cdf4a64

Browse files
author
Linus Torvalds
committed
Merge branch 'upstream' of git://git.infradead.org/~dedekind/ubi-2.6
* 'upstream' of git://git.infradead.org/~dedekind/ubi-2.6: (28 commits) UBI: fix compile warning UBI: fix error handling in erase worker UBI: fix comments UBI: remove unneeded error checks UBI: cleanup usage of try_module_get UBI: fix overflow bug UBI: bugfix in max_sqnum calculation UBI: bugfix in sqnum calculation UBI: fix signed-unsigned multiplication UBI: fix bug in atomic_leb_change() UBI: fix message UBI: fix debugging stuff UBI: bugfix in error path UBI: use is_power_of_2() UBI: fix freeing ubi->vtbl while unloading UBI: fix MAINTAINERS UBI: bugfix in ubi_leb_change() UBI: kill homegrown endian macros UBI: cleanup ioctl handling UBI: error path bugfix ...
2 parents 485cf92 + add0b43 commit cdf4a64

File tree

18 files changed

+403
-400
lines changed

18 files changed

+403
-400
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,7 @@ P: Artem Bityutskiy
23932393
23942394
W: http://www.linux-mtd.infradead.org/
23952395
2396-
T: git git://git.infradead.org/ubi-2.6.git
2396+
T: git git://git.infradead.org/~dedekind/ubi-2.6.git
23972397
S: Maintained
23982398

23992399
MICROTEK X6 SCANNER

drivers/mtd/ubi/build.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/moduleparam.h>
3434
#include <linux/stringify.h>
3535
#include <linux/stat.h>
36+
#include <linux/log2.h>
3637
#include "ubi.h"
3738

3839
/* Maximum length of the 'mtd=' parameter */
@@ -369,7 +370,7 @@ static int attach_by_scanning(struct ubi_device *ubi)
369370
out_wl:
370371
ubi_wl_close(ubi);
371372
out_vtbl:
372-
kfree(ubi->vtbl);
373+
vfree(ubi->vtbl);
373374
out_si:
374375
ubi_scan_destroy_si(si);
375376
return err;
@@ -422,8 +423,7 @@ static int io_init(struct ubi_device *ubi)
422423
ubi->hdrs_min_io_size = ubi->mtd->writesize >> ubi->mtd->subpage_sft;
423424

424425
/* Make sure minimal I/O unit is power of 2 */
425-
if (ubi->min_io_size == 0 ||
426-
(ubi->min_io_size & (ubi->min_io_size - 1))) {
426+
if (!is_power_of_2(ubi->min_io_size)) {
427427
ubi_err("bad min. I/O unit");
428428
return -EINVAL;
429429
}
@@ -593,8 +593,6 @@ static int attach_mtd_dev(const char *mtd_dev, int vid_hdr_offset,
593593
if (err)
594594
goto out_detach;
595595

596-
ubi_devices_cnt += 1;
597-
598596
ubi_msg("attached mtd%d to ubi%d", ubi->mtd->index, ubi_devices_cnt);
599597
ubi_msg("MTD device name: \"%s\"", ubi->mtd->name);
600598
ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20);
@@ -624,12 +622,13 @@ static int attach_mtd_dev(const char *mtd_dev, int vid_hdr_offset,
624622
wake_up_process(ubi->bgt_thread);
625623
}
626624

625+
ubi_devices_cnt += 1;
627626
return 0;
628627

629628
out_detach:
630629
ubi_eba_close(ubi);
631630
ubi_wl_close(ubi);
632-
kfree(ubi->vtbl);
631+
vfree(ubi->vtbl);
633632
out_free:
634633
kfree(ubi);
635634
out_mtd:
@@ -650,7 +649,7 @@ static void detach_mtd_dev(struct ubi_device *ubi)
650649
uif_close(ubi);
651650
ubi_eba_close(ubi);
652651
ubi_wl_close(ubi);
653-
kfree(ubi->vtbl);
652+
vfree(ubi->vtbl);
654653
put_mtd_device(ubi->mtd);
655654
kfree(ubi_devices[ubi_num]);
656655
ubi_devices[ubi_num] = NULL;
@@ -686,13 +685,6 @@ static int __init ubi_init(void)
686685
struct mtd_dev_param *p = &mtd_dev_param[i];
687686

688687
cond_resched();
689-
690-
if (!p->name) {
691-
dbg_err("empty name");
692-
err = -EINVAL;
693-
goto out_detach;
694-
}
695-
696688
err = attach_mtd_dev(p->name, p->vid_hdr_offs, p->data_offs);
697689
if (err)
698690
goto out_detach;
@@ -799,7 +791,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
799791

800792
/* Get rid of the final newline */
801793
if (buf[len - 1] == '\n')
802-
buf[len - 1] = 0;
794+
buf[len - 1] = '\0';
803795

804796
for (i = 0; i < 3; i++)
805797
tokens[i] = strsep(&pbuf, ",");
@@ -809,9 +801,6 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
809801
return -EINVAL;
810802
}
811803

812-
if (tokens[0] == '\0')
813-
return -EINVAL;
814-
815804
p = &mtd_dev_param[mtd_devs];
816805
strcpy(&p->name[0], tokens[0]);
817806

drivers/mtd/ubi/cdev.c

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static struct ubi_device *major_to_device(int major)
6464
if (ubi_devices[i] && ubi_devices[i]->major == major)
6565
return ubi_devices[i];
6666
BUG();
67+
return NULL;
6768
}
6869

6970
/**
@@ -153,7 +154,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
153154
ubi_warn("update of volume %d not finished, volume is damaged",
154155
vol->vol_id);
155156
vol->updating = 0;
156-
kfree(vol->upd_buf);
157+
vfree(vol->upd_buf);
157158
}
158159

159160
ubi_close_volume(desc);
@@ -232,7 +233,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
232233
tbuf_size = vol->usable_leb_size;
233234
if (count < tbuf_size)
234235
tbuf_size = ALIGN(count, ubi->min_io_size);
235-
tbuf = kmalloc(tbuf_size, GFP_KERNEL);
236+
tbuf = vmalloc(tbuf_size);
236237
if (!tbuf)
237238
return -ENOMEM;
238239

@@ -271,7 +272,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
271272
len = count > tbuf_size ? tbuf_size : count;
272273
} while (count);
273274

274-
kfree(tbuf);
275+
vfree(tbuf);
275276
return err ? err : count_save - count;
276277
}
277278

@@ -320,7 +321,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
320321
tbuf_size = vol->usable_leb_size;
321322
if (count < tbuf_size)
322323
tbuf_size = ALIGN(count, ubi->min_io_size);
323-
tbuf = kmalloc(tbuf_size, GFP_KERNEL);
324+
tbuf = vmalloc(tbuf_size);
324325
if (!tbuf)
325326
return -ENOMEM;
326327

@@ -355,7 +356,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
355356
len = count > tbuf_size ? tbuf_size : count;
356357
}
357358

358-
kfree(tbuf);
359+
vfree(tbuf);
359360
return err ? err : count_save - count;
360361
}
361362

@@ -397,6 +398,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
397398
vol->corrupted = 1;
398399
}
399400
vol->checked = 1;
401+
ubi_gluebi_updated(vol);
400402
revoke_exclusive(desc, UBI_READWRITE);
401403
}
402404

@@ -413,19 +415,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
413415
struct ubi_device *ubi = vol->ubi;
414416
void __user *argp = (void __user *)arg;
415417

416-
if (_IOC_NR(cmd) > VOL_CDEV_IOC_MAX_SEQ ||
417-
_IOC_TYPE(cmd) != UBI_VOL_IOC_MAGIC)
418-
return -ENOTTY;
419-
420-
if (_IOC_DIR(cmd) && _IOC_READ)
421-
err = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
422-
else if (_IOC_DIR(cmd) && _IOC_WRITE)
423-
err = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
424-
if (err)
425-
return -EFAULT;
426-
427418
switch (cmd) {
428-
429419
/* Volume update command */
430420
case UBI_IOCVOLUP:
431421
{
@@ -471,7 +461,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
471461
{
472462
int32_t lnum;
473463

474-
err = __get_user(lnum, (__user int32_t *)argp);
464+
err = get_user(lnum, (__user int32_t *)argp);
475465
if (err) {
476466
err = -EFAULT;
477467
break;
@@ -587,17 +577,6 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
587577
struct ubi_volume_desc *desc;
588578
void __user *argp = (void __user *)arg;
589579

590-
if (_IOC_NR(cmd) > UBI_CDEV_IOC_MAX_SEQ ||
591-
_IOC_TYPE(cmd) != UBI_IOC_MAGIC)
592-
return -ENOTTY;
593-
594-
if (_IOC_DIR(cmd) && _IOC_READ)
595-
err = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
596-
else if (_IOC_DIR(cmd) && _IOC_WRITE)
597-
err = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
598-
if (err)
599-
return -EFAULT;
600-
601580
if (!capable(CAP_SYS_RESOURCE))
602581
return -EPERM;
603582

@@ -612,7 +591,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
612591
struct ubi_mkvol_req req;
613592

614593
dbg_msg("create volume");
615-
err = __copy_from_user(&req, argp,
594+
err = copy_from_user(&req, argp,
616595
sizeof(struct ubi_mkvol_req));
617596
if (err) {
618597
err = -EFAULT;
@@ -629,7 +608,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
629608
if (err)
630609
break;
631610

632-
err = __put_user(req.vol_id, (__user int32_t *)argp);
611+
err = put_user(req.vol_id, (__user int32_t *)argp);
633612
if (err)
634613
err = -EFAULT;
635614

@@ -642,7 +621,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
642621
int vol_id;
643622

644623
dbg_msg("remove volume");
645-
err = __get_user(vol_id, (__user int32_t *)argp);
624+
err = get_user(vol_id, (__user int32_t *)argp);
646625
if (err) {
647626
err = -EFAULT;
648627
break;
@@ -669,7 +648,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
669648
struct ubi_rsvol_req req;
670649

671650
dbg_msg("re-size volume");
672-
err = __copy_from_user(&req, argp,
651+
err = copy_from_user(&req, argp,
673652
sizeof(struct ubi_rsvol_req));
674653
if (err) {
675654
err = -EFAULT;
@@ -707,7 +686,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
707686
struct file_operations ubi_cdev_operations = {
708687
.owner = THIS_MODULE,
709688
.ioctl = ubi_cdev_ioctl,
710-
.llseek = no_llseek
689+
.llseek = no_llseek,
711690
};
712691

713692
/* UBI volume character device operations */
@@ -718,5 +697,5 @@ struct file_operations ubi_vol_cdev_operations = {
718697
.llseek = vol_cdev_llseek,
719698
.read = vol_cdev_read,
720699
.write = vol_cdev_write,
721-
.ioctl = vol_cdev_ioctl
700+
.ioctl = vol_cdev_ioctl,
722701
};

drivers/mtd/ubi/debug.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
3636
{
3737
dbg_msg("erase counter header dump:");
38-
dbg_msg("magic %#08x", ubi32_to_cpu(ec_hdr->magic));
38+
dbg_msg("magic %#08x", be32_to_cpu(ec_hdr->magic));
3939
dbg_msg("version %d", (int)ec_hdr->version);
40-
dbg_msg("ec %llu", (long long)ubi64_to_cpu(ec_hdr->ec));
41-
dbg_msg("vid_hdr_offset %d", ubi32_to_cpu(ec_hdr->vid_hdr_offset));
42-
dbg_msg("data_offset %d", ubi32_to_cpu(ec_hdr->data_offset));
43-
dbg_msg("hdr_crc %#08x", ubi32_to_cpu(ec_hdr->hdr_crc));
40+
dbg_msg("ec %llu", (long long)be64_to_cpu(ec_hdr->ec));
41+
dbg_msg("vid_hdr_offset %d", be32_to_cpu(ec_hdr->vid_hdr_offset));
42+
dbg_msg("data_offset %d", be32_to_cpu(ec_hdr->data_offset));
43+
dbg_msg("hdr_crc %#08x", be32_to_cpu(ec_hdr->hdr_crc));
4444
dbg_msg("erase counter header hexdump:");
4545
ubi_dbg_hexdump(ec_hdr, UBI_EC_HDR_SIZE);
4646
}
@@ -52,20 +52,20 @@ void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr)
5252
void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr)
5353
{
5454
dbg_msg("volume identifier header dump:");
55-
dbg_msg("magic %08x", ubi32_to_cpu(vid_hdr->magic));
55+
dbg_msg("magic %08x", be32_to_cpu(vid_hdr->magic));
5656
dbg_msg("version %d", (int)vid_hdr->version);
5757
dbg_msg("vol_type %d", (int)vid_hdr->vol_type);
5858
dbg_msg("copy_flag %d", (int)vid_hdr->copy_flag);
5959
dbg_msg("compat %d", (int)vid_hdr->compat);
60-
dbg_msg("vol_id %d", ubi32_to_cpu(vid_hdr->vol_id));
61-
dbg_msg("lnum %d", ubi32_to_cpu(vid_hdr->lnum));
62-
dbg_msg("leb_ver %u", ubi32_to_cpu(vid_hdr->leb_ver));
63-
dbg_msg("data_size %d", ubi32_to_cpu(vid_hdr->data_size));
64-
dbg_msg("used_ebs %d", ubi32_to_cpu(vid_hdr->used_ebs));
65-
dbg_msg("data_pad %d", ubi32_to_cpu(vid_hdr->data_pad));
60+
dbg_msg("vol_id %d", be32_to_cpu(vid_hdr->vol_id));
61+
dbg_msg("lnum %d", be32_to_cpu(vid_hdr->lnum));
62+
dbg_msg("leb_ver %u", be32_to_cpu(vid_hdr->leb_ver));
63+
dbg_msg("data_size %d", be32_to_cpu(vid_hdr->data_size));
64+
dbg_msg("used_ebs %d", be32_to_cpu(vid_hdr->used_ebs));
65+
dbg_msg("data_pad %d", be32_to_cpu(vid_hdr->data_pad));
6666
dbg_msg("sqnum %llu",
67-
(unsigned long long)ubi64_to_cpu(vid_hdr->sqnum));
68-
dbg_msg("hdr_crc %08x", ubi32_to_cpu(vid_hdr->hdr_crc));
67+
(unsigned long long)be64_to_cpu(vid_hdr->sqnum));
68+
dbg_msg("hdr_crc %08x", be32_to_cpu(vid_hdr->hdr_crc));
6969
dbg_msg("volume identifier header hexdump:");
7070
}
7171

@@ -91,7 +91,7 @@ void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
9191

9292
if (vol->name_len <= UBI_VOL_NAME_MAX &&
9393
strnlen(vol->name, vol->name_len + 1) == vol->name_len) {
94-
dbg_msg("name %s", vol->name);
94+
dbg_msg("name %s", vol->name);
9595
} else {
9696
dbg_msg("the 1st 5 characters of the name: %c%c%c%c%c",
9797
vol->name[0], vol->name[1], vol->name[2],
@@ -106,30 +106,30 @@ void ubi_dbg_dump_vol_info(const struct ubi_volume *vol)
106106
*/
107107
void ubi_dbg_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx)
108108
{
109-
int name_len = ubi16_to_cpu(r->name_len);
109+
int name_len = be16_to_cpu(r->name_len);
110110

111111
dbg_msg("volume table record %d dump:", idx);
112-
dbg_msg("reserved_pebs %d", ubi32_to_cpu(r->reserved_pebs));
113-
dbg_msg("alignment %d", ubi32_to_cpu(r->alignment));
114-
dbg_msg("data_pad %d", ubi32_to_cpu(r->data_pad));
112+
dbg_msg("reserved_pebs %d", be32_to_cpu(r->reserved_pebs));
113+
dbg_msg("alignment %d", be32_to_cpu(r->alignment));
114+
dbg_msg("data_pad %d", be32_to_cpu(r->data_pad));
115115
dbg_msg("vol_type %d", (int)r->vol_type);
116116
dbg_msg("upd_marker %d", (int)r->upd_marker);
117117
dbg_msg("name_len %d", name_len);
118118

119119
if (r->name[0] == '\0') {
120-
dbg_msg("name NULL");
120+
dbg_msg("name NULL");
121121
return;
122122
}
123123

124124
if (name_len <= UBI_VOL_NAME_MAX &&
125125
strnlen(&r->name[0], name_len + 1) == name_len) {
126-
dbg_msg("name %s", &r->name[0]);
126+
dbg_msg("name %s", &r->name[0]);
127127
} else {
128128
dbg_msg("1st 5 characters of the name: %c%c%c%c%c",
129129
r->name[0], r->name[1], r->name[2], r->name[3],
130130
r->name[4]);
131131
}
132-
dbg_msg("crc %#08x", ubi32_to_cpu(r->crc));
132+
dbg_msg("crc %#08x", be32_to_cpu(r->crc));
133133
}
134134

135135
/**

drivers/mtd/ubi/debug.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ struct ubi_scan_volume;
5252
struct ubi_scan_leb;
5353
struct ubi_mkvol_req;
5454

55-
void ubi_dbg_print(int type, const char *func, const char *fmt, ...);
5655
void ubi_dbg_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr);
5756
void ubi_dbg_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr);
5857
void ubi_dbg_dump_vol_info(const struct ubi_volume *vol);
@@ -66,7 +65,6 @@ void ubi_dbg_hexdump(const void *buf, int size);
6665

6766
#define dbg_msg(fmt, ...) ({})
6867
#define ubi_dbg_dump_stack() ({})
69-
#define ubi_dbg_print(func, fmt, ...) ({})
7068
#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
7169
#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
7270
#define ubi_dbg_dump_vol_info(vol) ({})

0 commit comments

Comments
 (0)