Commit Graph

54 Commits (54b2c8f93d7c3ddc04b55666b878fec437d32983)

Author SHA1 Message Date
Jesper Juhl 54b2c8f93d UBI: silence a warning
This patch silences the following warning :

  drivers/mtd/ubi/vmt.c:73: warning: 'ret' may be used uninitialized in this function

gcc can't see that we always initialize ret in all situations where it is
actually used. The one case where it's not initialized is when we BUG(),
but gcc doesn't know that we won't then continue and use an uninitialized
'ret'.

This patch results in code that does exactely the same as before, but it
also makes gcc shut up, so we generate one less line of warning noise.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-12-26 19:15:14 +02:00
Artem Bityutskiy 393852ecfe UBI: add ubi_leb_map interface
The idea of this interface belongs to Adrian Hunter. The
interface is extremely useful when one has to have a guarantee
that an LEB will contain all 0xFFs even in case of an unclean
reboot. UBI does have an 'ubi_leb_erase()' call which may do
this, but it is stupid and ineffecient, because it flushes whole
queue. I should be re-worked to just be a pair of unmap,
map calls.

The user of the interfaci is UBIFS at the moment.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-12-26 19:15:14 +02:00
Artem Bityutskiy 94780d4de2 UBI: bugfix: allocate mandatory EBs first
First allocate the necessary eraseblocks, then the optional ones.
Otherwise it allocates all PEBs for bad EB handling, and fails
on then following EBA LEB allocation.

Reported-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-12-26 19:15:14 +02:00
Artem Bityutskiy 2362a53ec5 UBI: fix error code in ubi_io_read()
When NAND detects an ECC error, it returns -EBADMSG. It does not
stop reading requested data if one page has an ECC error, it keeps
going and reads all the requested data. If it fails to read all
the data, it does not return -EBADMSG, but returns the error code
which reflects the reason of the failure.

But some drivers may have bugs (e.g., OneNAND had) and stop reading
after the first ECC error, so it returns -EBADMSG. In turn, UBI
propagates this up to the caller. The caller will treat this as
"all the requested data was read, but there was an ECC error".

So we change the error code to -EIO if it is -EBADMSG and the read
length is less then the requested length. We also add an assertion,
so if UBI debugging is enabled, UBI will bug.

Pointed-to-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-12-26 19:15:13 +02:00
Pavel Emelyanov ba25f9dcc4 Use helpers to obtain task pid in printks
The task_struct->pid member is going to be deprecated, so start
using the helpers (task_pid_nr/task_pid_vnr/task_pid_nr_ns) in
the kernel.

The first thing to start with is the pid, printed to dmesg - in
this case we may safely use task_pid_nr(). Besides, printks produce
more (much more) than a half of all the explicit pid usage.

[akpm@linux-foundation.org: git-drm went and changed lots of stuff]
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Cc: Dave Airlie <airlied@linux.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-19 11:53:43 -07:00
Christoph Lameter 4ba9b9d0ba Slab API: remove useless ctor parameter and reorder parameters
Slab constructors currently have a flags parameter that is never used.  And
the order of the arguments is opposite to other slab functions.  The object
pointer is placed before the kmem_cache pointer.

Convert

        ctor(void *object, struct kmem_cache *s, unsigned long flags)

to

        ctor(struct kmem_cache *s, void *object)

throughout the kernel

[akpm@linux-foundation.org: coupla fixes]
Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-10-17 08:42:45 -07:00
David Woodhouse e3d18658d4 Merge branch 'master' of git://git.infradead.org/~dedekind/ubi-2.6 2007-10-14 14:29:00 +01:00
Artem Bityutskiy cc5f4f2875 UBI: return correct error code
Fix the following warning:

drivers/mtd/ubi/eba.c: In function 'ubi_eba_init_scan':
drivers/mtd/ubi/eba.c:1116: warning: 'err' may be used uninitialized in this function

Pointed-to-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:21 +03:00
Artem Bityutskiy 5abde384e3 UBI: remove useless inlines
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:21 +03:00
Artem Bityutskiy e8823bd63d UBI: fix atomic LEB change problems
When the UBI device is nearly full, i.e. all LEBs are mapped, we have
only one spare LEB left - the one we reserved for WL purposes. Well,
I do not count the LEBs which were reserved for bad PEB handling -
suppose NOR flash for simplicity. If an "atomic LEB change operation"
is run, and the WL unit is moving a LEB, we have no spare LEBs to
finish the operation and fail, which is not good. Moreover, if there
are 2 or more simultanious "atomic LEB change" requests, only one of
them has chances to succeed, the other will fail with -ENOSPC. Not
good either.

This patch does 2 things:
1. Reserves one PEB for the "atomic LEB change" operation.
2. Serealize the operations so that only on of them may run
   at a time (by means of a mutex).

Pointed-to-by: Brijesh Singh <brijesh.s.singh@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:21 +03:00
Artem Bityutskiy 6986646ba7 UBI: use byte hexdump
More handy since word hexdump prints in host endian.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:21 +03:00
Artem Bityutskiy e88d6e10e5 UBI: do not use vmalloc on I/O path
Similar reason as in case of the previous patch: it causes
deadlocks if a filesystem with writeback support works on top
of UBI. So pre-allocate needed buffers when attaching MTD device.
We also need mutexes to protect the buffers, but they do not
cause much contantion because they are used in recovery, torture,
and WL copy routines, which are called seldom.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:21 +03:00
Artem Bityutskiy 33818bbb84 UBI: allocate memory with GFP_NOFS
Use GFP_NOFS flag when allocating memory on I/O path, because otherwise
we may deadlock the filesystem which works on top of us. We observed
the deadlocks with UBIFS. Example:

VFS->FS lock a lock->UBI->kmalloc()->VFS writeback->FS locks the same
lock again.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:20 +03:00
Artem Bityutskiy ef6075fbfc UBI: use linux print_hex_dump(), not home-grown one
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:20 +03:00
Jesper Juhl 0169b49d52 UBI: don't use array index before testing if it is negative
I can't find anything guaranteeing that 'ubi_num' cannot be <0 in
drivers/mtd/ubi/kapi.c::ubi_open_volume(), and in fact the code
even tests for that and errors out if so. Unfortunately the test
for "ubi_num < 0" happens after we've already used 'ubi_num' as
an array index - bad thing to do if it is negative.
This patch moves the test earlier in the function and then moves
the indexing using that variable after the check. A bit safer :-)

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:20 +03:00
Artem Bityutskiy 8d2d4011f1 UBI: add more prints
I hit those situations and found out lack of print messages. Add more prints
when erase problems occur.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:20 +03:00
Artem Bityutskiy 8bc2296196 UBI: fix sparse warnings
Fix "symbol shadows an earlier one" warnings. Although they are harmless
but it does not hurt to fix them and make sparse happy.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:20 +03:00
Florin Malita dcec4c3bdc UBI: fix leak in ubi_scan_erase_peb
Coverity (1769) found the following problem: if the erase counter
overflow check triggers, ec_hdr is leaked.

Moving the allocation after the overflow check should take care of it.

Signed-off-by: Florin Malita <fmalita@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-10-14 13:10:20 +03:00
Mariusz Kozlowski d9b0744d6c [UBI] drivers/mtd/ubi/scan.c: kmalloc + memset conversion to kzalloc
To be able to convert kmalloc + memset(..., 1, ...) to kzalloc this patch
reverses the logic around 'buf'.

Signed-off-by: Mariusz Kozlowski <m.kozlowski@tuxland.pl>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
2007-08-01 11:04:05 +01:00
Paul Mundt 20c2df83d2 mm: Remove slab destructors from kmem_cache_create().
Slab destructors were no longer supported after Christoph's
c59def9f22 change. They've been
BUGs for both slab and slub, and slob never supported them
either.

This rips out support for the dtor pointer from kmem_cache_create()
completely and fixes up every single callsite in the kernel (there were
about 224, not including the slab allocator definitions themselves,
or the documentation references).

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
2007-07-20 10:11:58 +09:00
Paul Mundt add0b43ca6 UBI: fix compile warning
cdev.c whines in current git:

drivers/mtd/ubi/cdev.c: In function `major_to_device':
drivers/mtd/ubi/cdev.c:67: warning: control reaches end of non-void function

Shut it up.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:59:17 +03:00
Artem Bityutskiy 784c145444 UBI: fix error handling in erase worker
Do not switch to read-only mode in case of -EINTR and some
other obvious cases. Switch to RO mode only when we do not
know what is the error.

Reported-by: Vinit Agnihotri <vinit.agnihotri@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:59:09 +03:00
Artem Bityutskiy 63b6c1ed56 UBI: fix comments
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:59:01 +03:00
Artem Bityutskiy 503990ebb2 UBI: remove unneeded error checks
Pointed to by viro.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:58:53 +03:00
Fernando Luis Vázquez Cao 2db61c95c0 UBI: cleanup usage of try_module_get
The use of try_module_get(THIS_MODULE) in ubi_get_device_info does not
offer real protection against unexpected driver unloads, since we could
be preempted before try_modules_get gets executed. It is the caller who
should manipulate the refcounts. Besides, ubi_get_device_info is an
exported symbol which guarantees protection when accessed through
symbol_get.

Signed-off-by: Fernando Luis Vazquez Cao <fernando@oss.ntt.co.jp>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:58:45 +03:00
Vinit Agnihotri d08c3b78b8 UBI: fix overflow bug
I was experiencing overflows in multiplications for
volume->used_bytes in vmt.c & vtbl.c, while creating & resizing large volumes.

vol->used_bytes is long long however its 2 operands vol->used_ebs &
vol->usable_leb_size
are int. So their multiplication for larger values causes integer overflows.
Typecasting them solves the problem.

My machine & flash details:

64Bit dual-core AMD opteron, 1 GB RAM, linux 2.6.18.3.
mtd size = 6GB, volume size= 5GB, peb_size = 4MB.

heres patch which does the fix.

Signed-off-by: Vinit Agnihotri <vinit.agnihotri@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:58:12 +03:00
Artem Bityutskiy 2f3cdb55ee UBI: bugfix in max_sqnum calculation
Do not zero max_sqnum after a new volume has been found.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:58:02 +03:00
Brijesh Singh 76eafe479e UBI: bugfix in sqnum calculation
Hi,I came across problem of having two leb with same sequence no.This
happens when we continuously write one block again and again and reboot
machine before background thread erases those blocks.
The problem here was,when we find two blocks with same sequence no,we take
the higher one,but we were not updating max seq no,so next block may have
the same seqnum.
This patch solves this problem.

Signed-off-by: Brijesh Singh <brijesh.s.singh@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:57:52 +03:00
Brijesh Singh 2f176f7987 UBI: fix signed-unsigned multiplication
There is signed multiplication assigned to unsigned ei.addr in io.c.
This causes wrong addresses for big multiplication.This patch solves the
problem.

Signed-off-by: Brijesh Singh <brijesh.s.singh@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:57:34 +03:00
Artem Bityutskiy 84a9258062 UBI: fix bug in atomic_leb_change()
atomic_leb_change() is only allowed for dynamic volumes, so set
the volume type correctly.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:56:24 +03:00
Vinit Agnihotri a6ded48e34 UBI: fix message
Increase UBI devices couter after the message, not before.

Signed-off-by: Vinit Agnihotri <vinit.agnihotri@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:56:13 +03:00
Artem Bityutskiy b89044bfa0 UBI: fix debugging stuff
Do not check volumes which are currently in use because thay may be
in inconsistent state.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:56:05 +03:00
Artem Bityutskiy 94784d9164 UBI: bugfix in error path
When volume creation fails, we have to set ubi->volumes[vol_id]
back to NULL.

This patch also tweaks some debugging stuff.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:55:55 +03:00
Vignesh Babu 7753f1692f UBI: use is_power_of_2()
Replacing (n & (n-1)) in the context of power of 2 checks
with is_power_of_2

Signed-off-by: Vignesh Babu <vignesh.babu@wipro.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:55:26 +03:00
Vinit Agnihotri d7f0c4dc31 UBI: fix freeing ubi->vtbl while unloading
ubi->vtbl is allocated using vmalloc() in vtbl.c empty_create_lvol(),
but it is freed in build.c with kfree()

Signed-off-by: Vinit Agnihotri <vinit.agnihotri@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:54:15 +03:00
Artem Bityutskiy a443db48e0 UBI: bugfix in ubi_leb_change()
Do not call 'ubi_wl_put_peb()' if the LEB was unmapped.

Reported-by: Gabor Loki <loki@inf.u-szeged.hu>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:53:57 +03:00
Christoph Hellwig 3261ebd7d4 UBI: kill homegrown endian macros
Kill UBI's homegrown endianess handling and replace it with
the standard kernel endianess handling.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:53:49 +03:00
Christoph Hellwig bf07803a68 UBI: cleanup ioctl handling
- don't do access_ok + get/put user but use the proper macro
- remove useless checks

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:53:36 +03:00
Artem Bityutskiy 16d8cd7ce4 UBI: error path bugfix
No need to unlock the lock, this will be done at out_unlock.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:53:27 +03:00
Artem Bityutskiy f800f09bf4 UBI: minor comma fix
Use coma at the the last elements of structure initializer.

Daniel Stone's explanation:

Because it turns:
-   .attr   = foo
+   .attr   = foo,
+   .bar    = baz

into:
+   .bar    = baz,

i.e., far less likely to screw up a merge.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:53:17 +03:00
Artem Bityutskiy 92ad8f3750 UBI: use vmalloc for large buffers
UBI allocates temporary buffers of PEB size, which may be 256KiB.
Use vmalloc instead of kmalloc for such big temporary buffers.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:53:08 +03:00
Artem Bityutskiy 79b510c0f2 UBI: add few more comments
Add few comments above ubi_scan_add_used() to explain why it is so
complex. Requested by Satyam Sharma <satyam.sharma@gmail.com>.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:53:00 +03:00
Artem Bityutskiy 941dfb07ed UBI: set correct gluebi device size
In case of static volumes, make emulated MTD device size to
be equivalent to data size, rather then volume size.

Reported-by: John Smith <john@arrows.demon.co.uk>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:52:51 +03:00
Artem Bityutskiy 4ab60a0d7c UBI: do not let to read too much
In case of static volumes it is prohibited to read more data
then available.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:52:42 +03:00
Artem Bityutskiy 78d87c95b8 UBI: fix error path in create_vtbl()
There were several bugs in volume table creation error path. Thanks to
Satyam Sharma <satyam.sharma@gmail.com> and Florin Malita <fmalita@gmail.com>
for finding and analysing them: http://lkml.org/lkml/2007/5/3/274

This patch makes ubi_scan_add_to_list() static and renames it to
add_to_list(), just because it is not needed outside scan.c anymore.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:52:32 +03:00
Florin Malita c4e90ec013 UBI: fix dereference after kfree
Coverity (CID 1614) spotted new_seb being dereferenced after kfree() in
create_vtbl's write_error path.

Signed-off-by: Florin Malita <fmalita@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:52:22 +03:00
Artem Bityutskiy 341e1a0cf2 UBI: fix memory leak in checking code
Reported-by: Eric Sesterhenn / Snakebyte <snakebyte@gmx.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
2007-07-18 16:52:13 +03:00
Jeff Garzik a6343afb6e drivers/*: mark variables with uninitialized_var()
Mark variables in drivers/* with uninitialized_var() if such a warning
appears, and analysis proves that the var is initialized properly on all
paths it is used.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
2007-07-17 16:23:19 -04:00
Jeff Garzik 2ab934b8af drivers/mtd/ubi/eba: minor cleanup: tighten scope of a local var
Signed-off-by: Jeff Garzik <jeff@garzik.org>
2007-07-17 16:18:00 -04:00
Rafael J. Wysocki 8314418629 Freezer: make kernel threads nonfreezable by default
Currently, the freezer treats all tasks as freezable, except for the kernel
threads that explicitly set the PF_NOFREEZE flag for themselves.  This
approach is problematic, since it requires every kernel thread to either
set PF_NOFREEZE explicitly, or call try_to_freeze(), even if it doesn't
care for the freezing of tasks at all.

It seems better to only require the kernel threads that want to or need to
be frozen to use some freezer-related code and to remove any
freezer-related code from the other (nonfreezable) kernel threads, which is
done in this patch.

The patch causes all kernel threads to be nonfreezable by default (ie.  to
have PF_NOFREEZE set by default) and introduces the set_freezable()
function that should be called by the freezable kernel threads in order to
unset PF_NOFREEZE.  It also makes all of the currently freezable kernel
threads call set_freezable(), so it shouldn't cause any (intentional)
change of behaviour to appear.  Additionally, it updates documentation to
describe the freezing of tasks more accurately.

[akpm@linux-foundation.org: build fixes]
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Nigel Cunningham <nigel@nigel.suspend2.net>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Gautham R Shenoy <ego@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-17 10:23:02 -07:00