From: Grazvydas Ignotas Date: Wed, 20 Mar 2013 17:12:05 +0000 (+0200) Subject: Revert "staging: android: persistent_ram: make persistent_ram_write atomic" X-Git-Tag: sz_154~6 X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?p=pandora-kernel.git;a=commitdiff_plain;h=a409a7e2a635a8ade7adb23981993200a82e547e Revert "staging: android: persistent_ram: make persistent_ram_write atomic" This reverts commit 9ec12b4106cc43d27db79ef621afeaf8a430c842 (this atomic stuff causes data abort on OMAP3?) Conflicts: drivers/staging/android/persistent_ram.c --- diff --git a/drivers/staging/android/persistent_ram.c b/drivers/staging/android/persistent_ram.c index 8d8c1e33e0ff..86f0837a531f 100644 --- a/drivers/staging/android/persistent_ram.c +++ b/drivers/staging/android/persistent_ram.c @@ -27,8 +27,8 @@ struct persistent_ram_buffer { uint32_t sig; - atomic_t start; - atomic_t size; + uint32_t start; + uint32_t size; uint8_t data[0]; }; @@ -36,66 +36,6 @@ struct persistent_ram_buffer { static __initdata LIST_HEAD(persistent_ram_list); -static inline size_t buffer_size(struct persistent_ram_zone *prz) -{ - return atomic_read(&prz->buffer->size); -} - -static inline size_t buffer_start(struct persistent_ram_zone *prz) -{ - return atomic_read(&prz->buffer->start); -} - -/* increase and wrap the start pointer, returning the old value */ -static inline size_t buffer_start_add(struct persistent_ram_zone *prz, size_t a) -{ - int old; - int new; - - do { - old = atomic_read(&prz->buffer->start); - new = old + a; - while (unlikely(new > prz->buffer_size)) - new -= prz->buffer_size; - } while (atomic_cmpxchg(&prz->buffer->start, old, new) != old); - - return old; -} - -/* increase the size counter until it hits the max size */ -static inline void buffer_size_add(struct persistent_ram_zone *prz, size_t a) -{ - size_t old; - size_t new; - - if (atomic_read(&prz->buffer->size) == prz->buffer_size) - return; - - do { - old = atomic_read(&prz->buffer->size); - new = old + a; - if (new > prz->buffer_size) - new = prz->buffer_size; - } while (atomic_cmpxchg(&prz->buffer->size, old, new) != old); -} - -/* increase the size counter, retuning an error if it hits the max size */ -static inline ssize_t buffer_size_add_clamp(struct persistent_ram_zone *prz, - size_t a) -{ - size_t old; - size_t new; - - do { - old = atomic_read(&prz->buffer->size); - new = old + a; - if (new > prz->buffer_size) - return -ENOMEM; - } while (atomic_cmpxchg(&prz->buffer->size, old, new) != old); - - return 0; -} - static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz, uint8_t *data, size_t len, uint8_t *ecc) { @@ -122,7 +62,7 @@ static int persistent_ram_decode_rs8(struct persistent_ram_zone *prz, } static void notrace persistent_ram_update_ecc(struct persistent_ram_zone *prz, - unsigned int start, unsigned int count) + unsigned int count) { struct persistent_ram_buffer *buffer = prz->buffer; uint8_t *buffer_end = buffer->data + prz->buffer_size; @@ -135,16 +75,16 @@ static void notrace persistent_ram_update_ecc(struct persistent_ram_zone *prz, if (!prz->ecc) return; - block = buffer->data + (start & ~(ecc_block_size - 1)); - par = prz->par_buffer + (start / ecc_block_size) * prz->ecc_size; - + block = buffer->data + (buffer->start & ~(ecc_block_size - 1)); + par = prz->par_buffer + + (buffer->start / ecc_block_size) * prz->ecc_size; do { if (block + ecc_block_size > buffer_end) size = buffer_end - block; persistent_ram_encode_rs8(prz, block, size, par); block += ecc_block_size; par += ecc_size; - } while (block < buffer->data + start + count); + } while (block < buffer->data + buffer->start + count); } static void persistent_ram_update_header_ecc(struct persistent_ram_zone *prz) @@ -169,7 +109,7 @@ static void persistent_ram_ecc_old(struct persistent_ram_zone *prz) block = buffer->data; par = prz->par_buffer; - while (block < buffer->data + buffer_size(prz)) { + while (block < buffer->data + buffer->size) { int numerr; int size = prz->ecc_block_size; if (block + size > buffer->data + prz->buffer_size) @@ -259,33 +199,34 @@ ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz, } static void notrace persistent_ram_update(struct persistent_ram_zone *prz, - const void *s, unsigned int start, unsigned int count) + const void *s, unsigned int count) { struct persistent_ram_buffer *buffer = prz->buffer; - memcpy(buffer->data + start, s, count); - persistent_ram_update_ecc(prz, start, count); + memcpy(buffer->data + buffer->start, s, count); + persistent_ram_update_ecc(prz, count); } static void __init persistent_ram_save_old(struct persistent_ram_zone *prz) { struct persistent_ram_buffer *buffer = prz->buffer; - size_t size = buffer_size(prz); - size_t start = buffer_start(prz); + size_t old_log_size = buffer->size; char *dest; persistent_ram_ecc_old(prz); - dest = kmalloc(size, GFP_KERNEL); + dest = kmalloc(old_log_size, GFP_KERNEL); if (dest == NULL) { pr_err("persistent_ram: failed to allocate buffer\n"); return; } prz->old_log = dest; - prz->old_log_size = size; - memcpy(prz->old_log, &buffer->data[start], size - start); - memcpy(prz->old_log + size - start, &buffer->data[0], start); + prz->old_log_size = old_log_size; + memcpy(prz->old_log, + &buffer->data[buffer->start], buffer->size - buffer->start); + memcpy(prz->old_log + buffer->size - buffer->start, + &buffer->data[0], buffer->start); } int notrace persistent_ram_write(struct persistent_ram_zone *prz, @@ -293,26 +234,25 @@ int notrace persistent_ram_write(struct persistent_ram_zone *prz, { int rem; int c = count; - size_t start; + struct persistent_ram_buffer *buffer = prz->buffer; - if (unlikely(c > prz->buffer_size)) { + if (c > prz->buffer_size) { s += c - prz->buffer_size; c = prz->buffer_size; } - - buffer_size_add_clamp(prz, c); - - start = buffer_start_add(prz, c); - - rem = prz->buffer_size - start; - if (unlikely(rem < c)) { - persistent_ram_update(prz, s, start, rem); + rem = prz->buffer_size - buffer->start; + if (rem < c) { + persistent_ram_update(prz, s, rem); s += rem; c -= rem; - start = 0; + buffer->start = 0; + buffer->size = prz->buffer_size; } - persistent_ram_update(prz, s, start, c); + persistent_ram_update(prz, s, c); + buffer->start += c; + if (buffer->size < prz->buffer_size) + buffer->size += c; persistent_ram_update_header_ecc(prz); return count; @@ -421,25 +361,23 @@ struct persistent_ram_zone *__persistent_ram_init(struct device *dev, bool ecc) goto err; if (prz->buffer->sig == PERSISTENT_RAM_SIG) { - if (buffer_size(prz) > prz->buffer_size || - buffer_start(prz) > buffer_size(prz)) - pr_info("persistent_ram: found existing invalid buffer," - " size %ld, start %ld\n", - buffer_size(prz), buffer_start(prz)); + if (prz->buffer->size > prz->buffer_size + || prz->buffer->start > prz->buffer->size) + pr_info("persistent_ram: found existing invalid buffer, size %d, start %d\n", + prz->buffer->size, prz->buffer->start); else { - pr_info("persistent_ram: found existing buffer," - " size %ld, start %ld\n", - buffer_size(prz), buffer_start(prz)); + pr_info("persistent_ram: found existing buffer, size %d, start %d\n", + prz->buffer->size, prz->buffer->start); persistent_ram_save_old(prz); } } else { - pr_info("persistent_ram: no valid data in buffer" - " (sig = 0x%08x)\n", prz->buffer->sig); + pr_info("persistent_ram: no valid data in buffer (sig = 0x%08x)\n", + prz->buffer->sig); } prz->buffer->sig = PERSISTENT_RAM_SIG; - atomic_set(&prz->buffer->start, 0); - atomic_set(&prz->buffer->size, 0); + prz->buffer->start = 0; + prz->buffer->size = 0; return prz; err: