diff --git a/qdf/inc/qdf_file.h b/qdf/inc/qdf_file.h index 9ab401d027..8dd19a6ed3 100644 --- a/qdf/inc/qdf_file.h +++ b/qdf/inc/qdf_file.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved. + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -40,11 +41,30 @@ */ QDF_STATUS qdf_file_read(const char *path, char **out_buf); +/** + * qdf_file_read_bytes() - read the entire contents of a file and return the + * size read along with the content + * @path: the full path of the file to read + * @out_buf: double pointer for referring to the file contents buffer + * @out_buff_size: size of the contents read + * + * This API allocates a new, null-terminated buffer containing the contents of + * the file at @path. On success, @out_buf points to this new buffer, otherwise + * @out_buf is set to NULL. + * + * Consumers must free the allocated buffer by calling qdf_file_buf_free(). + * + * Return: QDF_STATUS + */ +QDF_STATUS qdf_file_read_bytes(const char *path, char **out_buf, + unsigned int *out_buff_size); + /** * qdf_file_buf_free() - free a previously allocated file buffer * @file_buf: pointer to the file buffer to free * - * This API is used in conjunction with qdf_file_read(). + * This API is used in conjunction with qdf_file_read() and + * qdf_file_read_bytes(). * * Return: None */ diff --git a/qdf/linux/src/qdf_file.c b/qdf/linux/src/qdf_file.c index b07f907d5c..19a89bfa21 100644 --- a/qdf/linux/src/qdf_file.c +++ b/qdf/linux/src/qdf_file.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2019, 2021 The Linux Foundation. All rights reserved. + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -121,3 +122,34 @@ void qdf_module_param_file_free(char *file_buf) qdf_untracked_mem_free(file_buf); } #endif + +QDF_STATUS qdf_file_read_bytes(const char *path, char **out_buf, + unsigned int *out_buff_size) +{ + int errno; + const struct firmware *fw; + char *buf; + + *out_buf = NULL; + + errno = qdf_firmware_request_nowarn(&fw, path, NULL); + if (errno) { + qdf_err("Failed to read file %s", path); + return QDF_STATUS_E_FAILURE; + } + + buf = qdf_mem_malloc(fw->size); + if (!buf) { + release_firmware(fw); + return QDF_STATUS_E_NOMEM; + } + + qdf_mem_copy(buf, fw->data, fw->size); + *out_buff_size = fw->size; + *out_buf = buf; + release_firmware(fw); + + return QDF_STATUS_SUCCESS; +} + +qdf_export_symbol(qdf_file_read_bytes);