Changeset ae7d03c in mainline for kernel/generic/src/log/log.c


Ignore:
Timestamp:
2018-05-10T13:39:19Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e8975278
Parents:
b277bef
git-author:
Jiri Svoboda <jiri@…> (2018-05-10 07:38:12)
git-committer:
Jiri Svoboda <jiri@…> (2018-05-10 13:39:19)
Message:

Selected ccheck-proposed comment fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/log/log.c

    rb277bef rae7d03c  
    6363
    6464/** Kernel log initialized */
    65 static atomic_t log_inited = {false};
     65static atomic_t log_inited = { false };
    6666
    6767/** Position in the cyclic buffer where the first log entry starts */
     
    9797}
    9898
    99 static size_t log_copy_from(uint8_t *data, size_t pos, size_t len) {
     99static size_t log_copy_from(uint8_t *data, size_t pos, size_t len)
     100{
    100101        for (size_t i = 0; i < len; i++, pos = (pos + 1) % LOG_LENGTH) {
    101102                data[i] = log_buffer[pos];
     
    104105}
    105106
    106 static size_t log_copy_to(const uint8_t *data, size_t pos, size_t len) {
     107static size_t log_copy_to(const uint8_t *data, size_t pos, size_t len)
     108{
    107109        for (size_t i = 0; i < len; i++, pos = (pos + 1) % LOG_LENGTH) {
    108110                log_buffer[pos] = data[i];
     
    170172 * This releases the log and output buffer locks.
    171173 */
    172 void log_end(void) {
     174void log_end(void)
     175{
    173176        /* Set the length in the header to correct value */
    174177        log_copy_to((uint8_t *) &log_current_len, log_current_start, sizeof(size_t));
     
    303306
    304307        switch (operation) {
    305                 case KLOG_WRITE:
    306                         data = (char *) malloc(size + 1, 0);
    307                         if (!data)
    308                                 return (sys_errno_t) ENOMEM;
    309 
    310                         rc = copy_from_uspace(data, buf, size);
    311                         if (rc) {
    312                                 free(data);
    313                                 return (sys_errno_t) rc;
     308        case KLOG_WRITE:
     309                data = (char *) malloc(size + 1, 0);
     310                if (!data)
     311                        return (sys_errno_t) ENOMEM;
     312
     313                rc = copy_from_uspace(data, buf, size);
     314                if (rc) {
     315                        free(data);
     316                        return (sys_errno_t) rc;
     317                }
     318                data[size] = 0;
     319
     320                if (level >= LVL_LIMIT)
     321                        level = LVL_NOTE;
     322
     323                log(LF_USPACE, level, "%s", data);
     324
     325                free(data);
     326                return EOK;
     327        case KLOG_READ:
     328                data = (char *) malloc(size, 0);
     329                if (!data)
     330                        return (sys_errno_t) ENOMEM;
     331
     332                size_t entry_len = 0;
     333                size_t copied = 0;
     334
     335                rc = EOK;
     336
     337                spinlock_lock(&log_lock);
     338
     339                while (next_for_uspace < log_used) {
     340                        size_t pos = (log_start + next_for_uspace) % LOG_LENGTH;
     341                        log_copy_from((uint8_t *) &entry_len, pos, sizeof(size_t));
     342
     343                        if (entry_len > PAGE_SIZE) {
     344                                /*
     345                                 * Since we limit data transfer
     346                                 * to uspace to a maximum of PAGE_SIZE
     347                                 * bytes, skip any entries larger
     348                                 * than this limit to prevent
     349                                 * userspace being stuck trying to
     350                                 * read them.
     351                                 */
     352                                next_for_uspace += entry_len;
     353                                continue;
    314354                        }
    315                         data[size] = 0;
    316 
    317                         if (level >= LVL_LIMIT)
    318                                 level = LVL_NOTE;
    319 
    320                         log(LF_USPACE, level, "%s", data);
    321 
     355
     356                        if (size < copied + entry_len) {
     357                                if (copied == 0)
     358                                        rc = EOVERFLOW;
     359                                break;
     360                        }
     361
     362                        log_copy_from((uint8_t *) (data + copied), pos, entry_len);
     363                        copied += entry_len;
     364                        next_for_uspace += entry_len;
     365                }
     366
     367                spinlock_unlock(&log_lock);
     368
     369                if (rc != EOK) {
    322370                        free(data);
    323                         return EOK;
    324                 case KLOG_READ:
    325                         data = (char *) malloc(size, 0);
    326                         if (!data)
    327                                 return (sys_errno_t) ENOMEM;
    328 
    329                         size_t entry_len = 0;
    330                         size_t copied = 0;
    331 
    332                         rc = EOK;
    333 
    334                         spinlock_lock(&log_lock);
    335 
    336                         while (next_for_uspace < log_used) {
    337                                 size_t pos = (log_start + next_for_uspace) % LOG_LENGTH;
    338                                 log_copy_from((uint8_t *) &entry_len, pos, sizeof(size_t));
    339 
    340                                 if (entry_len > PAGE_SIZE) {
    341                                         /*
    342                                          * Since we limit data transfer
    343                                          * to uspace to a maximum of PAGE_SIZE
    344                                          * bytes, skip any entries larger
    345                                          * than this limit to prevent
    346                                          * userspace being stuck trying to
    347                                          * read them.
    348                                          */
    349                                         next_for_uspace += entry_len;
    350                                         continue;
    351                                 }
    352 
    353                                 if (size < copied + entry_len) {
    354                                         if (copied == 0)
    355                                                 rc = EOVERFLOW;
    356                                         break;
    357                                 }
    358 
    359                                 log_copy_from((uint8_t *) (data + copied), pos, entry_len);
    360                                 copied += entry_len;
    361                                 next_for_uspace += entry_len;
    362                         }
    363 
    364                         spinlock_unlock(&log_lock);
    365 
    366                         if (rc != EOK) {
    367                                 free(data);
    368                                 return (sys_errno_t) rc;
    369                         }
    370 
    371                         rc = copy_to_uspace(buf, data, size);
    372 
    373                         free(data);
    374 
    375                         if (rc != EOK)
    376                                 return (sys_errno_t) rc;
    377 
    378                         return copy_to_uspace(uspace_nread, &copied, sizeof(copied));
    379                         return EOK;
    380                 default:
    381                         return (sys_errno_t) ENOTSUP;
     371                        return (sys_errno_t) rc;
     372                }
     373
     374                rc = copy_to_uspace(buf, data, size);
     375
     376                free(data);
     377
     378                if (rc != EOK)
     379                        return (sys_errno_t) rc;
     380
     381                return copy_to_uspace(uspace_nread, &copied, sizeof(copied));
     382                return EOK;
     383        default:
     384                return (sys_errno_t) ENOTSUP;
    382385        }
    383386}
Note: See TracChangeset for help on using the changeset viewer.