qcacmn: Add API qdf_file_read_bytes to read a file from host

Add an API qdf_file_read_bytes to read a file from within the driver
and return the contents of it along with its size.

Change-Id: If777e1b9c610e8cc7dd35be42fa9ced2bb1c6560
CRs-Fixed: 3456115
This commit is contained in:
Amith A
2023-04-19 10:10:28 +05:30
committed by Gerrit - the friendly Code Review server
parent 74c7a8d542
commit aed594f4b8
2 changed files with 53 additions and 1 deletions

View File

@@ -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
*/

View File

@@ -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);