aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/acpi/acpica/utprint.c44
-rw-r--r--tools/power/acpi/os_specific/service_layers/oslibcfs.c30
2 files changed, 43 insertions, 31 deletions
diff --git a/drivers/acpi/acpica/utprint.c b/drivers/acpi/acpica/utprint.c
index 9d5293fd992f..10311648f701 100644
--- a/drivers/acpi/acpica/utprint.c
+++ b/drivers/acpi/acpica/utprint.c
@@ -67,6 +67,11 @@ static char *acpi_ut_format_number(char *string,
67 67
68static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper); 68static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper);
69 69
70/* Module globals */
71
72static const char acpi_gbl_lower_hex_digits[] = "0123456789abcdef";
73static const char acpi_gbl_upper_hex_digits[] = "0123456789ABCDEF";
74
70/******************************************************************************* 75/*******************************************************************************
71 * 76 *
72 * FUNCTION: acpi_ut_bound_string_length 77 * FUNCTION: acpi_ut_bound_string_length
@@ -74,7 +79,7 @@ static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper);
74 * PARAMETERS: string - String with boundary 79 * PARAMETERS: string - String with boundary
75 * count - Boundary of the string 80 * count - Boundary of the string
76 * 81 *
77 * RETURN: Length of the string. 82 * RETURN: Length of the string. Less than or equal to Count.
78 * 83 *
79 * DESCRIPTION: Calculate the length of a string with boundary. 84 * DESCRIPTION: Calculate the length of a string with boundary.
80 * 85 *
@@ -114,8 +119,8 @@ static char *acpi_ut_bound_string_output(char *string, const char *end, char c)
114 if (string < end) { 119 if (string < end) {
115 *string = c; 120 *string = c;
116 } 121 }
117 ++string;
118 122
123 ++string;
119 return (string); 124 return (string);
120} 125}
121 126
@@ -137,14 +142,12 @@ static char *acpi_ut_bound_string_output(char *string, const char *end, char c)
137 142
138static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper) 143static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper)
139{ 144{
140 const char lower_digits[] = "0123456789abcdef";
141 const char upper_digits[] = "0123456789ABCDEF";
142 const char *digits; 145 const char *digits;
143 u64 digit_index; 146 u64 digit_index;
144 char *pos; 147 char *pos;
145 148
146 pos = string; 149 pos = string;
147 digits = upper ? upper_digits : lower_digits; 150 digits = upper ? acpi_gbl_upper_hex_digits : acpi_gbl_lower_hex_digits;
148 151
149 if (number == 0) { 152 if (number == 0) {
150 *(pos++) = '0'; 153 *(pos++) = '0';
@@ -155,8 +158,8 @@ static char *acpi_ut_put_number(char *string, u64 number, u8 base, u8 upper)
155 *(pos++) = digits[digit_index]; 158 *(pos++) = digits[digit_index];
156 } 159 }
157 } 160 }
158 /* *(Pos++) = '0'; */
159 161
162 /* *(Pos++) = '0'; */
160 return (pos); 163 return (pos);
161} 164}
162 165
@@ -181,8 +184,8 @@ const char *acpi_ut_scan_number(const char *string, u64 *number_ptr)
181 number *= 10; 184 number *= 10;
182 number += *(string++) - '0'; 185 number += *(string++) - '0';
183 } 186 }
184 *number_ptr = number;
185 187
188 *number_ptr = number;
186 return (string); 189 return (string);
187} 190}
188 191
@@ -211,8 +214,8 @@ const char *acpi_ut_print_number(char *string, u64 number)
211 while (pos1 != ascii_string) { 214 while (pos1 != ascii_string) {
212 *(pos2++) = *(--pos1); 215 *(pos2++) = *(--pos1);
213 } 216 }
214 *pos2 = 0;
215 217
218 *pos2 = 0;
216 return (string); 219 return (string);
217} 220}
218 221
@@ -246,11 +249,12 @@ static char *acpi_ut_format_number(char *string,
246 s32 i; 249 s32 i;
247 char reversed_string[66]; 250 char reversed_string[66];
248 251
249 /* Perform sanity checks */ 252 /* Parameter validation */
250 253
251 if (base < 2 || base > 16) { 254 if (base < 2 || base > 16) {
252 return NULL; 255 return (NULL);
253 } 256 }
257
254 if (type & ACPI_FORMAT_LEFT) { 258 if (type & ACPI_FORMAT_LEFT) {
255 type &= ~ACPI_FORMAT_ZERO; 259 type &= ~ACPI_FORMAT_ZERO;
256 } 260 }
@@ -294,6 +298,7 @@ static char *acpi_ut_format_number(char *string,
294 if (i > precision) { 298 if (i > precision) {
295 precision = i; 299 precision = i;
296 } 300 }
301
297 width -= precision; 302 width -= precision;
298 303
299 /* Output the string */ 304 /* Output the string */
@@ -318,6 +323,7 @@ static char *acpi_ut_format_number(char *string,
318 string = acpi_ut_bound_string_output(string, end, zero); 323 string = acpi_ut_bound_string_output(string, end, zero);
319 } 324 }
320 } 325 }
326
321 while (i <= --precision) { 327 while (i <= --precision) {
322 string = acpi_ut_bound_string_output(string, end, '0'); 328 string = acpi_ut_bound_string_output(string, end, '0');
323 } 329 }
@@ -341,7 +347,7 @@ static char *acpi_ut_format_number(char *string,
341 * format - Standard printf format 347 * format - Standard printf format
342 * args - Argument list 348 * args - Argument list
343 * 349 *
344 * RETURN: Size of successfully output bytes 350 * RETURN: Number of bytes actually written.
345 * 351 *
346 * DESCRIPTION: Formatted output to a string using argument list pointer. 352 * DESCRIPTION: Formatted output to a string using argument list pointer.
347 * 353 *
@@ -428,6 +434,7 @@ acpi_ut_vsnprintf(char *string,
428 if (*format == 'h' || *format == 'l' || *format == 'L') { 434 if (*format == 'h' || *format == 'l' || *format == 'L') {
429 qualifier = *format; 435 qualifier = *format;
430 ++format; 436 ++format;
437
431 if (qualifier == 'l' && *format == 'l') { 438 if (qualifier == 'l' && *format == 'l') {
432 qualifier = 'L'; 439 qualifier = 'L';
433 ++format; 440 ++format;
@@ -450,8 +457,10 @@ acpi_ut_vsnprintf(char *string,
450 ' '); 457 ' ');
451 } 458 }
452 } 459 }
460
453 c = (char)va_arg(args, int); 461 c = (char)va_arg(args, int);
454 pos = acpi_ut_bound_string_output(pos, end, c); 462 pos = acpi_ut_bound_string_output(pos, end, c);
463
455 while (--width > 0) { 464 while (--width > 0) {
456 pos = 465 pos =
457 acpi_ut_bound_string_output(pos, end, ' '); 466 acpi_ut_bound_string_output(pos, end, ' ');
@@ -512,10 +521,11 @@ acpi_ut_vsnprintf(char *string,
512 width = 2 * sizeof(void *); 521 width = 2 * sizeof(void *);
513 type |= ACPI_FORMAT_ZERO; 522 type |= ACPI_FORMAT_ZERO;
514 } 523 }
524
515 p = va_arg(args, void *); 525 p = va_arg(args, void *);
516 pos = acpi_ut_format_number(pos, end, 526 pos = acpi_ut_format_number(pos, end,
517 ACPI_TO_INTEGER(p), 527 ACPI_TO_INTEGER(p), 16,
518 16, width, precision, type); 528 width, precision, type);
519 continue; 529 continue;
520 530
521 default: 531 default:
@@ -552,6 +562,7 @@ acpi_ut_vsnprintf(char *string,
552 number = (signed int)number; 562 number = (signed int)number;
553 } 563 }
554 } 564 }
565
555 pos = acpi_ut_format_number(pos, end, number, base, 566 pos = acpi_ut_format_number(pos, end, number, base,
556 width, precision, type); 567 width, precision, type);
557 } 568 }
@@ -575,7 +586,7 @@ acpi_ut_vsnprintf(char *string,
575 * size - Boundary of the string 586 * size - Boundary of the string
576 * Format, ... - Standard printf format 587 * Format, ... - Standard printf format
577 * 588 *
578 * RETURN: Size of successfully output bytes 589 * RETURN: Number of bytes actually written.
579 * 590 *
580 * DESCRIPTION: Formatted output to a string. 591 * DESCRIPTION: Formatted output to a string.
581 * 592 *
@@ -602,7 +613,7 @@ int acpi_ut_snprintf(char *string, acpi_size size, const char *format, ...)
602 * format - Standard printf format 613 * format - Standard printf format
603 * args - Argument list 614 * args - Argument list
604 * 615 *
605 * RETURN: Size of successfully output bytes 616 * RETURN: Number of bytes actually written.
606 * 617 *
607 * DESCRIPTION: Formatted output to a file using argument list pointer. 618 * DESCRIPTION: Formatted output to a file using argument list pointer.
608 * 619 *
@@ -616,6 +627,7 @@ int acpi_ut_file_vprintf(ACPI_FILE file, const char *format, va_list args)
616 flags = acpi_os_acquire_lock(acpi_gbl_print_lock); 627 flags = acpi_os_acquire_lock(acpi_gbl_print_lock);
617 length = acpi_ut_vsnprintf(acpi_gbl_print_buffer, 628 length = acpi_ut_vsnprintf(acpi_gbl_print_buffer,
618 sizeof(acpi_gbl_print_buffer), format, args); 629 sizeof(acpi_gbl_print_buffer), format, args);
630
619 (void)acpi_os_write_file(file, acpi_gbl_print_buffer, length, 1); 631 (void)acpi_os_write_file(file, acpi_gbl_print_buffer, length, 1);
620 acpi_os_release_lock(acpi_gbl_print_lock, flags); 632 acpi_os_release_lock(acpi_gbl_print_lock, flags);
621 633
@@ -629,7 +641,7 @@ int acpi_ut_file_vprintf(ACPI_FILE file, const char *format, va_list args)
629 * PARAMETERS: file - File descriptor 641 * PARAMETERS: file - File descriptor
630 * Format, ... - Standard printf format 642 * Format, ... - Standard printf format
631 * 643 *
632 * RETURN: Size of successfully output bytes 644 * RETURN: Number of bytes actually written.
633 * 645 *
634 * DESCRIPTION: Formatted output to a file. 646 * DESCRIPTION: Formatted output to a file.
635 * 647 *
diff --git a/tools/power/acpi/os_specific/service_layers/oslibcfs.c b/tools/power/acpi/os_specific/service_layers/oslibcfs.c
index 2da0ce885c8c..c13ff9c51d74 100644
--- a/tools/power/acpi/os_specific/service_layers/oslibcfs.c
+++ b/tools/power/acpi/os_specific/service_layers/oslibcfs.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2 *
3 * Module Name: oslibcfs - C library OSL for file IO 3 * Module Name: oslibcfs - C library OSL for file I/O
4 * 4 *
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
@@ -64,8 +64,8 @@ ACPI_MODULE_NAME("oslibcfs")
64ACPI_FILE acpi_os_open_file(const char *path, u8 modes) 64ACPI_FILE acpi_os_open_file(const char *path, u8 modes)
65{ 65{
66 ACPI_FILE file; 66 ACPI_FILE file;
67 char modes_str[4];
68 u32 i = 0; 67 u32 i = 0;
68 char modes_str[4];
69 69
70 if (modes & ACPI_FILE_READING) { 70 if (modes & ACPI_FILE_READING) {
71 modes_str[i++] = 'r'; 71 modes_str[i++] = 'r';
@@ -76,6 +76,7 @@ ACPI_FILE acpi_os_open_file(const char *path, u8 modes)
76 if (modes & ACPI_FILE_BINARY) { 76 if (modes & ACPI_FILE_BINARY) {
77 modes_str[i++] = 'b'; 77 modes_str[i++] = 'b';
78 } 78 }
79
79 modes_str[i++] = '\0'; 80 modes_str[i++] = '\0';
80 81
81 file = fopen(path, modes_str); 82 file = fopen(path, modes_str);
@@ -90,11 +91,11 @@ ACPI_FILE acpi_os_open_file(const char *path, u8 modes)
90 * 91 *
91 * FUNCTION: acpi_os_close_file 92 * FUNCTION: acpi_os_close_file
92 * 93 *
93 * PARAMETERS: file - File descriptor 94 * PARAMETERS: file - An open file descriptor
94 * 95 *
95 * RETURN: None. 96 * RETURN: None.
96 * 97 *
97 * DESCRIPTION: Close a file. 98 * DESCRIPTION: Close a file opened via acpi_os_open_file.
98 * 99 *
99 ******************************************************************************/ 100 ******************************************************************************/
100 101
@@ -107,14 +108,14 @@ void acpi_os_close_file(ACPI_FILE file)
107 * 108 *
108 * FUNCTION: acpi_os_read_file 109 * FUNCTION: acpi_os_read_file
109 * 110 *
110 * PARAMETERS: file - File descriptor 111 * PARAMETERS: file - An open file descriptor
111 * buffer - Data buffer 112 * buffer - Data buffer
112 * size - Data block size 113 * size - Data block size
113 * count - Number of data blocks 114 * count - Number of data blocks
114 * 115 *
115 * RETURN: Size of successfully read buffer. 116 * RETURN: Number of bytes actually read.
116 * 117 *
117 * DESCRIPTION: Read a file. 118 * DESCRIPTION: Read from a file.
118 * 119 *
119 ******************************************************************************/ 120 ******************************************************************************/
120 121
@@ -135,14 +136,14 @@ acpi_os_read_file(ACPI_FILE file, void *buffer, acpi_size size, acpi_size count)
135 * 136 *
136 * FUNCTION: acpi_os_write_file 137 * FUNCTION: acpi_os_write_file
137 * 138 *
138 * PARAMETERS: file - File descriptor 139 * PARAMETERS: file - An open file descriptor
139 * buffer - Data buffer 140 * buffer - Data buffer
140 * size - Data block size 141 * size - Data block size
141 * count - Number of data blocks 142 * count - Number of data blocks
142 * 143 *
143 * RETURN: Size of successfully written buffer. 144 * RETURN: Number of bytes actually written.
144 * 145 *
145 * DESCRIPTION: Write a file. 146 * DESCRIPTION: Write to a file.
146 * 147 *
147 ******************************************************************************/ 148 ******************************************************************************/
148 149
@@ -164,9 +165,9 @@ acpi_os_write_file(ACPI_FILE file,
164 * 165 *
165 * FUNCTION: acpi_os_get_file_offset 166 * FUNCTION: acpi_os_get_file_offset
166 * 167 *
167 * PARAMETERS: file - File descriptor 168 * PARAMETERS: file - An open file descriptor
168 * 169 *
169 * RETURN: Size of current position. 170 * RETURN: Current file pointer position.
170 * 171 *
171 * DESCRIPTION: Get current file offset. 172 * DESCRIPTION: Get current file offset.
172 * 173 *
@@ -177,7 +178,6 @@ long acpi_os_get_file_offset(ACPI_FILE file)
177 long offset; 178 long offset;
178 179
179 offset = ftell(file); 180 offset = ftell(file);
180
181 return (offset); 181 return (offset);
182} 182}
183 183
@@ -185,8 +185,8 @@ long acpi_os_get_file_offset(ACPI_FILE file)
185 * 185 *
186 * FUNCTION: acpi_os_set_file_offset 186 * FUNCTION: acpi_os_set_file_offset
187 * 187 *
188 * PARAMETERS: file - File descriptor 188 * PARAMETERS: file - An open file descriptor
189 * offset - File offset 189 * offset - New file offset
190 * from - From begin/end of file 190 * from - From begin/end of file
191 * 191 *
192 * RETURN: Status 192 * RETURN: Status