From: Josh Law Date: Wed, 18 Mar 2026 15:59:17 +0000 (+0000) Subject: lib/bootconfig: use signed type for offset in xbc_init_node() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0f2199904188abd5477a6517a9ce525bdc2dc01d;p=thirdparty%2Fkernel%2Flinux.git lib/bootconfig: use signed type for offset in xbc_init_node() lib/bootconfig.c:415:32: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion] Pointer subtraction yields ptrdiff_t (signed), which was stored in unsigned long. The original unsigned type implicitly caught a negative offset (data < xbc_data) because the wrapped value would exceed XBC_DATA_MAX. Make this intent explicit by using a signed long and adding an offset < 0 check to the WARN_ON condition. Link: https://lore.kernel.org/all/20260318155919.78168-12-objecting@objecting.org/ Signed-off-by: Josh Law Signed-off-by: Masami Hiramatsu (Google) --- diff --git a/lib/bootconfig.c b/lib/bootconfig.c index 9f059bb68e410..1f84748607b42 100644 --- a/lib/bootconfig.c +++ b/lib/bootconfig.c @@ -412,9 +412,9 @@ const char * __init xbc_node_find_next_key_value(struct xbc_node *root, static int __init xbc_init_node(struct xbc_node *node, char *data, uint16_t flag) { - unsigned long offset = data - xbc_data; + long offset = data - xbc_data; - if (WARN_ON(offset >= XBC_DATA_MAX)) + if (WARN_ON(offset < 0 || offset >= XBC_DATA_MAX)) return -EINVAL; node->data = (uint16_t)offset | flag;