aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/utilities/utalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/utilities/utalloc.c')
-rw-r--r--drivers/acpi/utilities/utalloc.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 7dcb67e0b215..241c535c1753 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -232,7 +232,7 @@ acpi_status acpi_ut_validate_buffer(struct acpi_buffer * buffer)
232 * RETURN: Status 232 * RETURN: Status
233 * 233 *
234 * DESCRIPTION: Validate that the buffer is of the required length or 234 * DESCRIPTION: Validate that the buffer is of the required length or
235 * allocate a new buffer. Returned buffer is always zeroed. 235 * allocate a new buffer. Returned buffer is always zeroed.
236 * 236 *
237 ******************************************************************************/ 237 ******************************************************************************/
238 238
@@ -240,7 +240,7 @@ acpi_status
240acpi_ut_initialize_buffer(struct acpi_buffer * buffer, 240acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
241 acpi_size required_length) 241 acpi_size required_length)
242{ 242{
243 acpi_status status = AE_OK; 243 acpi_size input_buffer_length;
244 244
245 /* Parameter validation */ 245 /* Parameter validation */
246 246
@@ -248,55 +248,58 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
248 return (AE_BAD_PARAMETER); 248 return (AE_BAD_PARAMETER);
249 } 249 }
250 250
251 switch (buffer->length) { 251 /*
252 * Buffer->Length is used as both an input and output parameter. Get the
253 * input actual length and set the output required buffer length.
254 */
255 input_buffer_length = buffer->length;
256 buffer->length = required_length;
257
258 /*
259 * The input buffer length contains the actual buffer length, or the type
260 * of buffer to be allocated by this routine.
261 */
262 switch (input_buffer_length) {
252 case ACPI_NO_BUFFER: 263 case ACPI_NO_BUFFER:
253 264
254 /* Set the exception and returned the required length */ 265 /* Return the exception (and the required buffer length) */
255 266
256 status = AE_BUFFER_OVERFLOW; 267 return (AE_BUFFER_OVERFLOW);
257 break;
258 268
259 case ACPI_ALLOCATE_BUFFER: 269 case ACPI_ALLOCATE_BUFFER:
260 270
261 /* Allocate a new buffer */ 271 /* Allocate a new buffer */
262 272
263 buffer->pointer = acpi_os_allocate(required_length); 273 buffer->pointer = acpi_os_allocate(required_length);
264 if (!buffer->pointer) {
265 return (AE_NO_MEMORY);
266 }
267
268 /* Clear the buffer */
269
270 ACPI_MEMSET(buffer->pointer, 0, required_length);
271 break; 274 break;
272 275
273 case ACPI_ALLOCATE_LOCAL_BUFFER: 276 case ACPI_ALLOCATE_LOCAL_BUFFER:
274 277
275 /* Allocate a new buffer with local interface to allow tracking */ 278 /* Allocate a new buffer with local interface to allow tracking */
276 279
277 buffer->pointer = ACPI_ALLOCATE_ZEROED(required_length); 280 buffer->pointer = ACPI_ALLOCATE(required_length);
278 if (!buffer->pointer) {
279 return (AE_NO_MEMORY);
280 }
281 break; 281 break;
282 282
283 default: 283 default:
284 284
285 /* Existing buffer: Validate the size of the buffer */ 285 /* Existing buffer: Validate the size of the buffer */
286 286
287 if (buffer->length < required_length) { 287 if (input_buffer_length < required_length) {
288 status = AE_BUFFER_OVERFLOW; 288 return (AE_BUFFER_OVERFLOW);
289 break;
290 } 289 }
290 break;
291 }
291 292
292 /* Clear the buffer */ 293 /* Validate allocation from above or input buffer pointer */
293 294
294 ACPI_MEMSET(buffer->pointer, 0, required_length); 295 if (!buffer->pointer) {
295 break; 296 return (AE_NO_MEMORY);
296 } 297 }
297 298
298 buffer->length = required_length; 299 /* Have a valid buffer, clear it */
299 return (status); 300
301 ACPI_MEMSET(buffer->pointer, 0, required_length);
302 return (AE_OK);
300} 303}
301 304
302#ifdef NOT_USED_BY_LINUX 305#ifdef NOT_USED_BY_LINUX