From nobody Mon Dec 15 23:19:50 2025 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2023BB48 for ; Mon, 15 Dec 2025 12:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765801263; cv=none; b=IDtW7fiAkDBTm3GhingYdcsEMwIqXQoovn66Z7PXbczWIMpzoj2/pqx4TySUw5LRrbuopCp+BZNhZ1M7mIe/f0Ha6U6Wxn6KIXOtjG+uJxXeBB3cPCjrsgRjrBHfALXHWL1ygrxwNyaexhz0hnpm0nnlLn0obJVzzxrRx2F/Hyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765801263; c=relaxed/simple; bh=tGtZFWJZWVieQAfbdvhspv4bnWH397mqfaAyuWKdKCo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iehEOdBDtUGCRil8Kkn+9ZZPn+NB078mcQhzVUxotioKgPdZagFKELN/oVQHMhR//Sf0AQCoRUJqmYVgUq/UIqqiP2Uei5tiWPXcOG6MHgjUGw+KCuzOWZFQz0IvSDsisUnP5QNZMeDqAcIi77mQ4+pNrSnPR1pTI6HfoE84/Jk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cLz7lVcn; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cLz7lVcn" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765801260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=kuuh4h814MG9F8RlFOMcprDr38lqFWabL2fokFxEL8A=; b=cLz7lVcnpKV5OzwgZIxw0/aWGA02m/Y1GJ1M2JmgTwCdkRb6ErZd/DMyREsTRXPmavJXbv Sb7XpJCTdiIX6vniUBqse6R+QQGXNt4LZFAusW0/WFS9y60ScBzjlaT7UOBx5u/8zVUqxt Ig/9re6rPlt+aSRQN7rIddBKmL8Gq48= From: Thorsten Blum To: Johannes Berg Cc: Thorsten Blum , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next] net: rfkill: Replace strcpy with memcpy to improve rfkill_alloc Date: Mon, 15 Dec 2025 13:20:36 +0100 Message-ID: <20251215122036.379322-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" strcpy() is deprecated [1] and uses an additional strlen() internally; use memcpy() directly since we already know the length of 'name' and that it is guaranteed to be NUL-terminated. Use struct_size(), which provides additional compile-time checks for structures with flexible array members (e.g., __must_be_array()), to determine the allocation size for a new 'struct rfkill'. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy= [1] Signed-off-by: Thorsten Blum --- net/rfkill/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 7d3e82e4c2fc..db1260acb182 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -986,6 +986,7 @@ struct rfkill * __must_check rfkill_alloc(const char *n= ame, { struct rfkill *rfkill; struct device *dev; + size_t name_sz; =20 if (WARN_ON(!ops)) return NULL; @@ -999,14 +1000,15 @@ struct rfkill * __must_check rfkill_alloc(const char= *name, if (WARN_ON(type =3D=3D RFKILL_TYPE_ALL || type >=3D NUM_RFKILL_TYPES)) return NULL; =20 - rfkill =3D kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL); + name_sz =3D strlen(name) + 1; + rfkill =3D kzalloc(struct_size(rfkill, name, name_sz), GFP_KERNEL); if (!rfkill) return NULL; =20 spin_lock_init(&rfkill->lock); INIT_LIST_HEAD(&rfkill->node); rfkill->type =3D type; - strcpy(rfkill->name, name); + memcpy(rfkill->name, name, name_sz); rfkill->ops =3D ops; rfkill->data =3D ops_data; =20 --=20 Thorsten Blum GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4