Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

earlycpio.c: Fix the confusing comment of find_cpio_data().

The comments of find_cpio_data() says:

* @offset: When a matching file is found, this is the offset to the
* beginning of the cpio. ......

But according to the code,

dptr = PTR_ALIGN(p + ch[C_NAMESIZE], 4);
nptr = PTR_ALIGN(dptr + ch[C_FILESIZE], 4);
....
*offset = (long)nptr - (long)data; /* data is the cpio file */

@offset is the offset of the next file, not the matching file itself.
This is confused and may cause unnecessary waste of time to debug.
So fix it.

As Tejun Heo suggested, rename @offset to @nextoff which is more clear
to users. And also adjust the new comments.

Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
Reviewed-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Reviewed-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Tang Chen and committed by
Rafael J. Wysocki
598bae70 d7b2c3d8

+14 -13
+14 -13
lib/earlycpio.c
··· 49 49 50 50 /** 51 51 * cpio_data find_cpio_data - Search for files in an uncompressed cpio 52 - * @path: The directory to search for, including a slash at the end 53 - * @data: Pointer to the the cpio archive or a header inside 54 - * @len: Remaining length of the cpio based on data pointer 55 - * @offset: When a matching file is found, this is the offset to the 56 - * beginning of the cpio. It can be used to iterate through 57 - * the cpio to find all files inside of a directory path 52 + * @path: The directory to search for, including a slash at the end 53 + * @data: Pointer to the the cpio archive or a header inside 54 + * @len: Remaining length of the cpio based on data pointer 55 + * @nextoff: When a matching file is found, this is the offset from the 56 + * beginning of the cpio to the beginning of the next file, not the 57 + * matching file itself. It can be used to iterate through the cpio 58 + * to find all files inside of a directory path. 58 59 * 59 - * @return: struct cpio_data containing the address, length and 60 - * filename (with the directory path cut off) of the found file. 61 - * If you search for a filename and not for files in a directory, 62 - * pass the absolute path of the filename in the cpio and make sure 63 - * the match returned an empty filename string. 60 + * @return: struct cpio_data containing the address, length and 61 + * filename (with the directory path cut off) of the found file. 62 + * If you search for a filename and not for files in a directory, 63 + * pass the absolute path of the filename in the cpio and make sure 64 + * the match returned an empty filename string. 64 65 */ 65 66 66 67 struct cpio_data find_cpio_data(const char *path, void *data, 67 - size_t len, long *offset) 68 + size_t len, long *nextoff) 68 69 { 69 70 const size_t cpio_header_len = 8*C_NFIELDS - 2; 70 71 struct cpio_data cd = { NULL, 0, "" }; ··· 125 124 if ((ch[C_MODE] & 0170000) == 0100000 && 126 125 ch[C_NAMESIZE] >= mypathsize && 127 126 !memcmp(p, path, mypathsize)) { 128 - *offset = (long)nptr - (long)data; 127 + *nextoff = (long)nptr - (long)data; 129 128 if (ch[C_NAMESIZE] - mypathsize >= MAX_CPIO_FILE_NAME) { 130 129 pr_warn( 131 130 "File %s exceeding MAX_CPIO_FILE_NAME [%d]\n",