Rev 6131 | Rev 6660 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6131 | Rev 6296 | ||
---|---|---|---|
Line 248... | Line 248... | ||
248 | { |
248 | { |
249 | return c | 0x20; |
249 | return c | 0x20; |
250 | } |
250 | } |
Line 251... | Line -... | ||
251 | - | ||
252 | - | ||
253 | //const char hex_asc[] = "0123456789abcdef"; |
- | |
254 | - | ||
255 | /** |
- | |
256 | * hex_to_bin - convert a hex digit to its real value |
- | |
257 | * @ch: ascii character represents hex digit |
- | |
258 | * |
- | |
259 | * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad |
- | |
260 | * input. |
- | |
261 | */ |
- | |
262 | int hex_to_bin(char ch) |
- | |
263 | { |
- | |
264 | if ((ch >= '0') && (ch <= '9')) |
- | |
265 | return ch - '0'; |
- | |
266 | ch = tolower(ch); |
- | |
267 | if ((ch >= 'a') && (ch <= 'f')) |
- | |
268 | return ch - 'a' + 10; |
- | |
269 | return -1; |
- | |
270 | } |
- | |
271 | EXPORT_SYMBOL(hex_to_bin); |
- | |
272 | - | ||
273 | /** |
- | |
274 | * hex2bin - convert an ascii hexadecimal string to its binary representation |
- | |
275 | * @dst: binary result |
- | |
276 | * @src: ascii hexadecimal string |
- | |
277 | * @count: result length |
- | |
278 | * |
- | |
279 | * Return 0 on success, -1 in case of bad input. |
- | |
280 | */ |
- | |
281 | int hex2bin(u8 *dst, const char *src, size_t count) |
- | |
282 | { |
- | |
283 | while (count--) { |
- | |
284 | int hi = hex_to_bin(*src++); |
- | |
285 | int lo = hex_to_bin(*src++); |
- | |
286 | - | ||
287 | if ((hi < 0) || (lo < 0)) |
- | |
288 | return -1; |
- | |
289 | - | ||
290 | *dst++ = (hi << 4) | lo; |
- | |
291 | } |
- | |
292 | return 0; |
- | |
293 | } |
- | |
294 | EXPORT_SYMBOL(hex2bin); |
- | |
295 | - | ||
296 | /** |
- | |
297 | * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory |
- | |
298 | * @buf: data blob to dump |
- | |
299 | * @len: number of bytes in the @buf |
- | |
300 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
- | |
301 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
- | |
302 | * @linebuf: where to put the converted data |
- | |
303 | * @linebuflen: total size of @linebuf, including space for terminating NUL |
- | |
304 | * @ascii: include ASCII after the hex output |
- | |
305 | * |
- | |
306 | * hex_dump_to_buffer() works on one "line" of output at a time, i.e., |
- | |
307 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
- | |
308 | * |
- | |
309 | * Given a buffer of u8 data, hex_dump_to_buffer() converts the input data |
- | |
310 | * to a hex + ASCII dump at the supplied memory location. |
- | |
311 | * The converted output is always NUL-terminated. |
- | |
312 | * |
- | |
313 | * E.g.: |
- | |
314 | * hex_dump_to_buffer(frame->data, frame->len, 16, 1, |
- | |
315 | * linebuf, sizeof(linebuf), true); |
- | |
316 | * |
- | |
317 | * example output buffer: |
- | |
318 | * 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
- | |
319 | */ |
- | |
320 | int hex_dump_to_buffer(const void *buf, size_t len, int rowsize, int groupsize, |
- | |
321 | char *linebuf, size_t linebuflen, bool ascii) |
- | |
322 | { |
- | |
323 | const u8 *ptr = buf; |
- | |
324 | int ngroups; |
- | |
325 | u8 ch; |
- | |
326 | int j, lx = 0; |
- | |
327 | int ascii_column; |
- | |
328 | int ret; |
- | |
329 | - | ||
330 | if (rowsize != 16 && rowsize != 32) |
- | |
331 | rowsize = 16; |
- | |
332 | - | ||
333 | if (len > rowsize) /* limit to one line at a time */ |
- | |
334 | len = rowsize; |
- | |
335 | if (!is_power_of_2(groupsize) || groupsize > 8) |
- | |
336 | groupsize = 1; |
- | |
337 | if ((len % groupsize) != 0) /* no mixed size output */ |
- | |
338 | groupsize = 1; |
- | |
339 | - | ||
340 | ngroups = len / groupsize; |
- | |
341 | ascii_column = rowsize * 2 + rowsize / groupsize + 1; |
- | |
342 | - | ||
343 | if (!linebuflen) |
- | |
344 | goto overflow1; |
- | |
345 | - | ||
346 | if (!len) |
- | |
347 | goto nil; |
- | |
348 | - | ||
349 | if (groupsize == 8) { |
- | |
350 | const u64 *ptr8 = buf; |
- | |
351 | - | ||
352 | for (j = 0; j < ngroups; j++) { |
- | |
353 | ret = snprintf(linebuf + lx, linebuflen - lx, |
- | |
354 | "%s%16.16llx", j ? " " : "", |
- | |
355 | (unsigned long long)*(ptr8 + j)); |
- | |
356 | if (ret >= linebuflen - lx) |
- | |
357 | goto overflow1; |
- | |
358 | lx += ret; |
- | |
359 | } |
- | |
360 | } else if (groupsize == 4) { |
- | |
361 | const u32 *ptr4 = buf; |
- | |
362 | - | ||
363 | for (j = 0; j < ngroups; j++) { |
- | |
364 | ret = snprintf(linebuf + lx, linebuflen - lx, |
- | |
365 | "%s%8.8x", j ? " " : "", |
- | |
366 | *(ptr4 + j)); |
- | |
367 | if (ret >= linebuflen - lx) |
- | |
368 | goto overflow1; |
- | |
369 | lx += ret; |
- | |
370 | } |
- | |
371 | } else if (groupsize == 2) { |
- | |
372 | const u16 *ptr2 = buf; |
- | |
373 | - | ||
374 | for (j = 0; j < ngroups; j++) { |
- | |
375 | ret = snprintf(linebuf + lx, linebuflen - lx, |
- | |
376 | "%s%4.4x", j ? " " : "", |
- | |
377 | *(ptr2 + j)); |
- | |
378 | if (ret >= linebuflen - lx) |
- | |
379 | goto overflow1; |
- | |
380 | lx += ret; |
- | |
381 | } |
- | |
382 | } else { |
- | |
383 | for (j = 0; j < len; j++) { |
- | |
384 | if (linebuflen < lx + 3) |
- | |
385 | goto overflow2; |
- | |
386 | ch = ptr[j]; |
- | |
387 | linebuf[lx++] = hex_asc_hi(ch); |
- | |
388 | linebuf[lx++] = hex_asc_lo(ch); |
- | |
389 | linebuf[lx++] = ' '; |
- | |
390 | } |
- | |
391 | if (j) |
- | |
392 | lx--; |
- | |
393 | } |
- | |
394 | if (!ascii) |
- | |
395 | goto nil; |
- | |
396 | - | ||
397 | while (lx < ascii_column) { |
- | |
398 | if (linebuflen < lx + 2) |
- | |
399 | goto overflow2; |
- | |
400 | linebuf[lx++] = ' '; |
- | |
401 | } |
- | |
402 | for (j = 0; j < len; j++) { |
- | |
403 | if (linebuflen < lx + 2) |
- | |
404 | goto overflow2; |
- | |
405 | ch = ptr[j]; |
- | |
406 | linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.'; |
- | |
407 | } |
- | |
408 | nil: |
- | |
409 | linebuf[lx] = '\0'; |
- | |
410 | return lx; |
- | |
411 | overflow2: |
- | |
412 | linebuf[lx++] = '\0'; |
- | |
413 | overflow1: |
- | |
414 | return ascii ? ascii_column + len : (groupsize * 2 + 1) * ngroups - 1; |
- | |
415 | } |
- | |
416 | /** |
- | |
417 | * print_hex_dump - print a text hex dump to syslog for a binary blob of data |
- | |
418 | * @level: kernel log level (e.g. KERN_DEBUG) |
- | |
419 | * @prefix_str: string to prefix each line with; |
- | |
420 | * caller supplies trailing spaces for alignment if desired |
- | |
421 | * @prefix_type: controls whether prefix of an offset, address, or none |
- | |
422 | * is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE) |
- | |
423 | * @rowsize: number of bytes to print per line; must be 16 or 32 |
- | |
424 | * @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1) |
- | |
425 | * @buf: data blob to dump |
- | |
426 | * @len: number of bytes in the @buf |
- | |
427 | * @ascii: include ASCII after the hex output |
- | |
428 | * |
- | |
429 | * Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump |
- | |
430 | * to the kernel log at the specified kernel log level, with an optional |
- | |
431 | * leading prefix. |
- | |
432 | * |
- | |
433 | * print_hex_dump() works on one "line" of output at a time, i.e., |
- | |
434 | * 16 or 32 bytes of input data converted to hex + ASCII output. |
- | |
435 | * print_hex_dump() iterates over the entire input @buf, breaking it into |
- | |
436 | * "line size" chunks to format and print. |
- | |
437 | * |
- | |
438 | * E.g.: |
- | |
439 | * print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS, |
- | |
440 | * 16, 1, frame->data, frame->len, true); |
- | |
441 | * |
- | |
442 | * Example output using %DUMP_PREFIX_OFFSET and 1-byte mode: |
- | |
443 | * 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO |
- | |
444 | * Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode: |
- | |
445 | * ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~. |
- | |
446 | */ |
- | |
447 | void print_hex_dump(const char *level, const char *prefix_str, int prefix_type, |
- | |
448 | int rowsize, int groupsize, |
- | |
449 | const void *buf, size_t len, bool ascii) |
- | |
450 | { |
- | |
451 | const u8 *ptr = buf; |
- | |
452 | int i, linelen, remaining = len; |
- | |
453 | unsigned char linebuf[32 * 3 + 2 + 32 + 1]; |
- | |
454 | - | ||
455 | if (rowsize != 16 && rowsize != 32) |
- | |
456 | rowsize = 16; |
- | |
457 | - | ||
458 | for (i = 0; i < len; i += rowsize) { |
- | |
459 | linelen = min(remaining, rowsize); |
- | |
460 | remaining -= rowsize; |
- | |
461 | - | ||
462 | hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize, |
- | |
463 | linebuf, sizeof(linebuf), ascii); |
- | |
464 | - | ||
465 | switch (prefix_type) { |
- | |
466 | case DUMP_PREFIX_ADDRESS: |
- | |
467 | printk("%s%s%p: %s\n", |
- | |
468 | level, prefix_str, ptr + i, linebuf); |
- | |
469 | break; |
- | |
470 | case DUMP_PREFIX_OFFSET: |
- | |
471 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf); |
- | |
472 | break; |
- | |
473 | default: |
- | |
474 | printk("%s%s%s\n", level, prefix_str, linebuf); |
- | |
475 | break; |
- | |
476 | } |
- | |
477 | } |
- | |
478 | } |
- | |
479 | - | ||
480 | void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
- | |
481 | const void *buf, size_t len) |
- | |
482 | { |
- | |
483 | print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, 16, 1, |
- | |
484 | buf, len, true); |
- | |
485 | } |
251 | |
486 | 252 | ||
487 | void *kmemdup(const void *src, size_t len, gfp_t gfp) |
253 | void *kmemdup(const void *src, size_t len, gfp_t gfp) |
Line 488... | Line 254... | ||
488 | { |
254 | { |
Line 781... | Line 547... | ||
781 | __printf(2, 3) int seq_printf(struct seq_file *m, const char *f, ...) |
547 | __printf(2, 3) int seq_printf(struct seq_file *m, const char *f, ...) |
782 | { |
548 | { |
783 | return 0; |
549 | return 0; |
784 | } |
550 | } |
Line 785... | Line -... | ||
785 | - | ||
786 | - | ||
787 | signed long |
- | |
788 | fence_wait_timeout(struct fence *fence, bool intr, signed long timeout) |
- | |
789 | { |
- | |
790 | signed long ret; |
- | |
791 | - | ||
792 | if (WARN_ON(timeout < 0)) |
- | |
793 | return -EINVAL; |
- | |
794 | - | ||
795 | // trace_fence_wait_start(fence); |
- | |
796 | ret = fence->ops->wait(fence, intr, timeout); |
- | |
797 | // trace_fence_wait_end(fence); |
- | |
798 | return ret; |
- | |
799 | } |
- | |
800 | - | ||
801 | void fence_release(struct kref *kref) |
- | |
802 | { |
- | |
803 | struct fence *fence = |
- | |
804 | container_of(kref, struct fence, refcount); |
- | |
805 | - | ||
806 | // trace_fence_destroy(fence); |
- | |
807 | - | ||
808 | BUG_ON(!list_empty(&fence->cb_list)); |
- | |
809 | - | ||
810 | if (fence->ops->release) |
- | |
811 | fence->ops->release(fence); |
- | |
812 | else |
- | |
813 | fence_free(fence); |
- | |
814 | } |
- | |
815 | - | ||
816 | void fence_free(struct fence *fence) |
- | |
817 | { |
- | |
818 | kfree_rcu(fence, rcu); |
- | |
819 | } |
- | |
820 | EXPORT_SYMBOL(fence_free); |
- | |
821 | - | ||
822 | 551 | ||
823 | ktime_t ktime_get(void) |
552 | ktime_t ktime_get(void) |
824 | { |
553 | { |
Line 825... | Line 554... | ||
825 | ktime_t t; |
554 | ktime_t t; |