From nobody Thu Apr 2 19:00:23 2026 Received: from mail-dl1-f49.google.com (mail-dl1-f49.google.com [74.125.82.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB2DA34CFC6 for ; Fri, 27 Mar 2026 03:03:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774580611; cv=none; b=pcTqQLQOOJyBgkIjMaxyDQWIa0U8auxQkACEOqaQjk608xxGMbjucSNuzvQD05jmLdrprPCLrChcbEAow9gJ0xHO5SWMg/lPDgu6XI41v3z/pQDpWwJHm3hqATuqeUfc1Rf/hAjzuE8nifJ0P9AOQvcxV2diI0tQTFafK5yrCqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774580611; c=relaxed/simple; bh=GWG5hZy1veFdtnzqyHdYWLrPolKgR7bSn7NtmrJOIFs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dwoDT9UZEsfYPbFiLa5OBMPnBGkSoUR4XQRT6TUAiRjwDzA4yojzCzcXkpDeLEkNkuiEhGZGdSQGSpXnYZ+2r0mgybQLQBIvasiIy79lF2/dBILjYe+dlLu/lglLC2TnUKHDS2P0bMA5GSI8E1oBwKUjA04vlqCQ0bF5D7tgmZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LTOFxOjV; arc=none smtp.client-ip=74.125.82.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LTOFxOjV" Received: by mail-dl1-f49.google.com with SMTP id a92af1059eb24-12a80c36350so1984626c88.1 for ; Thu, 26 Mar 2026 20:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774580609; x=1775185409; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=vSaSNFof8LDeaSt87Ybd7wXF7naIBHoN3VgDG9Jp8yE=; b=LTOFxOjVus0teg82jxGyS+KYCrJ1FWKK2MI3ZpSsJcdm44SAy8XwVrunuRYoaMjyOD 66LZLrMxg2MdGRYrlfsqso8yOxkJgweF4tdZ0AXkunF2+2piCWZsNULhR5XTejHEcBUO NMevfhhjdVLsbRn3NIezCSUPoVt/utHQFJ10ZU2gk34siaTEtFMfv1c7iuut1Qjz2NCF Lhpk6hOjln/LepNS/NrXPBvg4hjMX6NQgfAiOMqh0YgUF+NFJ/8BPyrZZd3ZYOv/6uxy 9sswud72udfY5zmRaKZFWYESRdgQZI9zP1ERFzRALhGD70OUTWhz1zxR8hk1o+EdieKn lR5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774580609; x=1775185409; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vSaSNFof8LDeaSt87Ybd7wXF7naIBHoN3VgDG9Jp8yE=; b=ofOa3qZlKjRCAfVcntBJE0kWtT5/WrdUFpFvhdK1ISFSKSJ9IDvEXwrG2sdLPOarkj cwRX4+IoUF5N9gvn0UxFsaWFbGhg1Sd+XpvJBMgzeUdE2pSKzdO0zoA5tXVHWmd9qcnc wgcWN0mtBXYV7GO6ppnMxjiFW+QL9Yj2cauqQcVWBFw+8Z1jsCwCj5vW0hi64ja16Jar vPRw4xoLfbOfnZpk0XfAoD0ady7RKi2vfeqqL8Wc5YxMA1v0oWpToTAZFEDWEI+ylWbi xy83rnrr+IG94Bt3VvHCicIR6fzDQUHnl0c5drH8BccpS4VM1GTHiom/H5ntp48sC0jO TUzw== X-Forwarded-Encrypted: i=1; AJvYcCXlfQzCkCEU6iEvxrjdG/fMZNYeMjMj2d9WW3PKR3KZRzoMEu/NXloqeeS5XkIol9QgOuEDsL01Y2S0HwY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4AwrJ2pnGU3XfbNDK6W1BajCbGxnLcDwLY6WZlxc4rFqLCVu0 ZPKRTRA3zXn0XcSz3FHiF+AmtjvlyTjTO2K8nXiPIztf4BvWoxami3M0S70AkCMn X-Gm-Gg: ATEYQzxMExdjvnBDezG2YN39FXN3M+NtVPzdbJYQxuPyDrQMxhAbq24BmjWOgXygZwW 4ZUh8pepGRzSBq1bTVJjQl26ZQTnKuWnJiRHP6VgjfbIEdXwIZHDIi+C6sAFP6+gOqHtg6Q48ub LXfHToir2eYKQpQliIWryvM9Xd45wFTbsgCB7m84n2NLKCj/2TrPu8JyQjC4Tk9fR77OYtwcgot K60PdOqn9G1sHqYw9DoKTGBtovwE05ksiqaltiffRQJ7HCMb8D3fN2TgPqrRmVLVS8FDWjKPfaX nDAqPcTPHpwl2XuRiout/9f3Wkpxxad9ohKzigoOEprGYLUzMehhTwsmSMSmjHVPNznIINx3H9H A6GyYfTJcmxlw+WqyvJG80Pi5akp8SNXLpVND7YGUHAOmOA2OnwQuWZqEdTK50HxVSUE1YA5NJM 5hS2SahTPsbDkWi5aJqNMOPaSjo+Drz1+e5FE6uIUBzqN1YeV1QwZmA94= X-Received: by 2002:a05:7022:220a:b0:128:d7a7:526f with SMTP id a92af1059eb24-12ab284be71mr452177c88.4.1774580608570; Thu, 26 Mar 2026 20:03:28 -0700 (PDT) Received: from ryzen ([2601:644:8000:5b5d::8bd]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12aa78462fesm6576388c88.15.2026.03.26.20.03.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 20:03:27 -0700 (PDT) From: Rosen Penev To: linux-i2c@vger.kernel.org Cc: Tomi Valkeinen , Luca Ceresoli , Wolfram Sang , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH] i2c: atr: use kzalloc_flex Date: Thu, 26 Mar 2026 20:03:10 -0700 Message-ID: <20260327030310.8502-1-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 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 Content-Type: text/plain; charset="utf-8" Convert kzalloc_obj + kcalloc to kzalloc_flex to save an allocation. Add __counted_by to get extra runtime analysis. Signed-off-by: Rosen Penev Reviewed-by: Luca Ceresoli --- drivers/i2c/i2c-atr.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/i2c-atr.c b/drivers/i2c/i2c-atr.c index f9fcb4793aaf..e6d2af659d81 100644 --- a/drivers/i2c/i2c-atr.c +++ b/drivers/i2c/i2c-atr.c @@ -49,8 +49,8 @@ struct i2c_atr_alias_pair { * @shared: Indicates if this alias pool is shared by multiple channels * * @lock: Lock protecting @aliases and @use_mask - * @aliases: Array of aliases, must hold exactly @size elements * @use_mask: Mask of used aliases + * @aliases: Array of aliases, must hold exactly @size elements */ struct i2c_atr_alias_pool { size_t size; @@ -58,8 +58,8 @@ struct i2c_atr_alias_pool { =20 /* Protects aliases and use_mask */ spinlock_t lock; - u16 *aliases; unsigned long *use_mask; + u16 aliases[] __counted_by(size); }; =20 /** @@ -137,22 +137,16 @@ static struct i2c_atr_alias_pool *i2c_atr_alloc_alias= _pool(size_t num_aliases, b struct i2c_atr_alias_pool *alias_pool; int ret; =20 - alias_pool =3D kzalloc_obj(*alias_pool); + alias_pool =3D kzalloc_flex(*alias_pool, aliases, num_aliases); if (!alias_pool) return ERR_PTR(-ENOMEM); =20 alias_pool->size =3D num_aliases; =20 - alias_pool->aliases =3D kcalloc(num_aliases, sizeof(*alias_pool->aliases)= , GFP_KERNEL); - if (!alias_pool->aliases) { - ret =3D -ENOMEM; - goto err_free_alias_pool; - } - alias_pool->use_mask =3D bitmap_zalloc(num_aliases, GFP_KERNEL); if (!alias_pool->use_mask) { ret =3D -ENOMEM; - goto err_free_aliases; + goto err_free_alias_pool; } =20 alias_pool->shared =3D shared; @@ -161,8 +155,6 @@ static struct i2c_atr_alias_pool *i2c_atr_alloc_alias_p= ool(size_t num_aliases, b =20 return alias_pool; =20 -err_free_aliases: - kfree(alias_pool->aliases); err_free_alias_pool: kfree(alias_pool); return ERR_PTR(ret); @@ -171,7 +163,6 @@ static struct i2c_atr_alias_pool *i2c_atr_alloc_alias_p= ool(size_t num_aliases, b static void i2c_atr_free_alias_pool(struct i2c_atr_alias_pool *alias_pool) { bitmap_free(alias_pool->use_mask); - kfree(alias_pool->aliases); kfree(alias_pool); } =20 --=20 2.53.0