Loading drivers/char/diag/diag_memorydevice.c +28 −11 Original line number Diff line number Diff line Loading @@ -110,14 +110,15 @@ void diag_md_close_all() entry = &ch->tbl[j]; if (entry->len <= 0) continue; spin_lock_irqsave(&ch->lock, flags); if (ch->ops && ch->ops->write_done) ch->ops->write_done(entry->buf, entry->len, entry->ctx, ch->ctx); spin_lock_irqsave(&entry->lock, flags); entry->ctx, DIAG_MEMORY_DEVICE_MODE); entry->buf = NULL; entry->len = 0; entry->ctx = 0; spin_unlock_irqrestore(&entry->lock, flags); spin_unlock_irqrestore(&ch->lock, flags); } } Loading @@ -138,8 +139,23 @@ int diag_md_write(int id, unsigned char *buf, int len, int ctx) return -EINVAL; ch = &diag_md[id]; spin_lock_irqsave(&ch->lock, flags); for (i = 0; i < ch->num_tbl_entries && !found; i++) { if (ch->tbl[i].buf != buf) continue; found = 1; pr_err_ratelimited("diag: trying to write the same buffer buf: %p, ctxt: %d len: %d at i: %d back to the table, proc: %d, mode: %d\n", buf, ctx, ch->tbl[i].len, i, id, driver->logging_mode); } spin_unlock_irqrestore(&ch->lock, flags); if (found) return -ENOMEM; spin_lock_irqsave(&ch->lock, flags); for (i = 0; i < ch->num_tbl_entries && !found; i++) { spin_lock_irqsave(&ch->tbl[i].lock, flags); if (ch->tbl[i].len == 0) { ch->tbl[i].buf = buf; ch->tbl[i].len = len; Loading @@ -147,8 +163,8 @@ int diag_md_write(int id, unsigned char *buf, int len, int ctx) found = 1; diag_ws_on_read(DIAG_WS_MUX, len); } spin_unlock_irqrestore(&ch->tbl[i].lock, flags); } spin_unlock_irqrestore(&ch->lock, flags); if (!found) { pr_err_ratelimited("diag: Unable to find an empty space in table, please reduce logging rate, proc: %d\n", Loading Loading @@ -240,15 +256,16 @@ int diag_md_copy_to_user(char __user *buf, int *pret, size_t buf_size) */ num_data++; drop_data: spin_lock_irqsave(&ch->lock, flags); if (ch->ops && ch->ops->write_done) ch->ops->write_done(entry->buf, entry->len, entry->ctx, DIAG_MEMORY_DEVICE_MODE); diag_ws_on_copy(DIAG_WS_MUX); spin_lock_irqsave(&entry->lock, flags); entry->buf = NULL; entry->len = 0; entry->ctx = 0; spin_unlock_irqrestore(&entry->lock, flags); spin_unlock_irqrestore(&ch->lock, flags); } } Loading Loading @@ -279,7 +296,7 @@ int diag_md_init() ch->tbl[j].buf = NULL; ch->tbl[j].len = 0; ch->tbl[j].ctx = 0; spin_lock_init(&(ch->tbl[j].lock)); spin_lock_init(&(ch->lock)); } } Loading drivers/char/diag/diag_memorydevice.h +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ struct diag_buf_tbl_t { unsigned char *buf; int len; int ctx; spinlock_t lock; }; struct diag_md_info { Loading @@ -39,6 +38,7 @@ struct diag_md_info { int ctx; int mempool; int num_tbl_entries; spinlock_t lock; struct diag_buf_tbl_t *tbl; struct diag_mux_ops *ops; }; Loading Loading
drivers/char/diag/diag_memorydevice.c +28 −11 Original line number Diff line number Diff line Loading @@ -110,14 +110,15 @@ void diag_md_close_all() entry = &ch->tbl[j]; if (entry->len <= 0) continue; spin_lock_irqsave(&ch->lock, flags); if (ch->ops && ch->ops->write_done) ch->ops->write_done(entry->buf, entry->len, entry->ctx, ch->ctx); spin_lock_irqsave(&entry->lock, flags); entry->ctx, DIAG_MEMORY_DEVICE_MODE); entry->buf = NULL; entry->len = 0; entry->ctx = 0; spin_unlock_irqrestore(&entry->lock, flags); spin_unlock_irqrestore(&ch->lock, flags); } } Loading @@ -138,8 +139,23 @@ int diag_md_write(int id, unsigned char *buf, int len, int ctx) return -EINVAL; ch = &diag_md[id]; spin_lock_irqsave(&ch->lock, flags); for (i = 0; i < ch->num_tbl_entries && !found; i++) { if (ch->tbl[i].buf != buf) continue; found = 1; pr_err_ratelimited("diag: trying to write the same buffer buf: %p, ctxt: %d len: %d at i: %d back to the table, proc: %d, mode: %d\n", buf, ctx, ch->tbl[i].len, i, id, driver->logging_mode); } spin_unlock_irqrestore(&ch->lock, flags); if (found) return -ENOMEM; spin_lock_irqsave(&ch->lock, flags); for (i = 0; i < ch->num_tbl_entries && !found; i++) { spin_lock_irqsave(&ch->tbl[i].lock, flags); if (ch->tbl[i].len == 0) { ch->tbl[i].buf = buf; ch->tbl[i].len = len; Loading @@ -147,8 +163,8 @@ int diag_md_write(int id, unsigned char *buf, int len, int ctx) found = 1; diag_ws_on_read(DIAG_WS_MUX, len); } spin_unlock_irqrestore(&ch->tbl[i].lock, flags); } spin_unlock_irqrestore(&ch->lock, flags); if (!found) { pr_err_ratelimited("diag: Unable to find an empty space in table, please reduce logging rate, proc: %d\n", Loading Loading @@ -240,15 +256,16 @@ int diag_md_copy_to_user(char __user *buf, int *pret, size_t buf_size) */ num_data++; drop_data: spin_lock_irqsave(&ch->lock, flags); if (ch->ops && ch->ops->write_done) ch->ops->write_done(entry->buf, entry->len, entry->ctx, DIAG_MEMORY_DEVICE_MODE); diag_ws_on_copy(DIAG_WS_MUX); spin_lock_irqsave(&entry->lock, flags); entry->buf = NULL; entry->len = 0; entry->ctx = 0; spin_unlock_irqrestore(&entry->lock, flags); spin_unlock_irqrestore(&ch->lock, flags); } } Loading Loading @@ -279,7 +296,7 @@ int diag_md_init() ch->tbl[j].buf = NULL; ch->tbl[j].len = 0; ch->tbl[j].ctx = 0; spin_lock_init(&(ch->tbl[j].lock)); spin_lock_init(&(ch->lock)); } } Loading
drivers/char/diag/diag_memorydevice.h +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ struct diag_buf_tbl_t { unsigned char *buf; int len; int ctx; spinlock_t lock; }; struct diag_md_info { Loading @@ -39,6 +38,7 @@ struct diag_md_info { int ctx; int mempool; int num_tbl_entries; spinlock_t lock; struct diag_buf_tbl_t *tbl; struct diag_mux_ops *ops; }; Loading