[PATCH v2 04/19] net/xsc: add xsc device init and uninit

Stephen Hemminger stephen at networkplumber.org
Wed Sep 11 05:47:48 CEST 2024


On Wed, 11 Sep 2024 10:07:25 +0800
"WanRenyong" <wanry at yunsilicon.com> wrote:

> +
> +	sprintf(path, "%s/device/uevent", dev_path);

better to use snprintf for safety

> +	while (fgets(line, sizeof(line), file) == line) {
> +		size_t len = strlen(line);
> +
> +		/* Truncate long lines. */
> +		if (len == (sizeof(line) - 1)) {
> +			while (line[(len - 1)] != '\n') {
> +				int n = fgetc(file);
> +
> +				if (n == EOF)
> +					goto out;
> +				line[(len - 1)] = n;
> +			}
> +			/* No match for long lines. */
> +			continue;
> +		}

If you have to deal with long lines better to use something
like getline() that handles arbitrary length.


More information about the dev mailing list