From patchwork Mon Oct 23 18:32:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 157029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1480005vqx; Mon, 23 Oct 2023 11:33:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQxC8N4mjiqejPv2bVoDktEUHiEoMiKkbDMsSzWEPtZRCYQsNojo1LsGawOHeQM6G3KcTM X-Received: by 2002:a05:6a21:798a:b0:14d:4ab5:5e34 with SMTP id bh10-20020a056a21798a00b0014d4ab55e34mr361306pzc.51.1698086001686; Mon, 23 Oct 2023 11:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698086001; cv=none; d=google.com; s=arc-20160816; b=wVjMjnIFUfjoQcZ2HOrOfm5wsPhNkEr9QZkU2YMLyui4K1dodK/5/lcOwyvBU4nFzz af0fHtTYY7s936E0geNfV1YaTF1jczda2mNautckG6swPYCZ00HZvf8yqNUPPgHn4YM/ pROZ7cZZ740Zw252+S4Jems9IjRe7uS+zGE43d1ZDHgYBjFxRMJsVH1cCEx5ydPI3HhM +1bCAsvdg79D6t30vPpDe4sG3wYPihtsCyiTIQl5oAf+RyyEgN1OIZzNhQ+81GzLW+hS UDx9rNB2vDOLRH/Xt0e9UGB/RJZt1RO1Rnref2jKhjdBFBExXW/n46ZhVo48DGRj4lpk M5Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FMjgweLhTo5SkdcoVkpbQPkyPY7V0wNxVnhTVFmu8Uw=; fh=BqhVhkt11hdmkbujRH8QIfD2cez9lYpeRoddPZBJma8=; b=BZnnmLJ2ZX5TwNf8fCwftXzoCsc8oKbk8kA8nx3dTUEVRuNFKuLQ4fhsTZYHAmH6sC UciyyvuC7Eank8tfD9nH6ywpqKOdo/F9tn4N/7PMGFGSW0Z2C/r5XK4N6j31vTSBTTgb 2zrEHmE+yM7+lOnY7OW2pcwSBMs+ejGBplI8QNLBbwZH7wegcmolUWDjJnPseueaU5o5 Vp+tgF1YX3I10KEGf66mxjyiDrib1Sfio6s9VnvgYti7HAODvw0Gyv7+z/7RvbFVGX6G uyC7NJu22Pl3E7jeMfX5yASYTeXyLzaLv3E/TcDlPnDHRD3xYho7khKlBmcgy/q5NtJa k2wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="emNSBpG/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b2-20020a17090a990200b002777ce4c9e6si6892189pjp.72.2023.10.23.11.33.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 11:33:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="emNSBpG/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A136C8032C58; Mon, 23 Oct 2023 11:33:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbjJWSdK (ORCPT + 27 others); Mon, 23 Oct 2023 14:33:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231222AbjJWSdJ (ORCPT ); Mon, 23 Oct 2023 14:33:09 -0400 Received: from out.smtpout.orange.fr (out-15.smtpout.orange.fr [193.252.22.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA551B7 for ; Mon, 23 Oct 2023 11:33:05 -0700 (PDT) Received: from localhost.localdomain ([89.207.171.96]) by smtp.orange.fr with ESMTPSA id uzjXqFyhBlciauzjaqWBr8; Mon, 23 Oct 2023 20:33:03 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698085983; bh=FMjgweLhTo5SkdcoVkpbQPkyPY7V0wNxVnhTVFmu8Uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=emNSBpG/a9z3B1LDISJdjQaKSpJTUuKZpDTHiYtYZlavdx3+54rvcUgu0Cn2sHtnl 3FOcFQnp8G5lOpqX9RY0+ui+ci8ifYkIARA+gttPtI+ytelf1TlFTL80WgtS0+yRFe BAmDhOQYLMaQgpbMSW30h0IIfvUfSwQl1o3aEz/t5HqWgKGFN0G1nj+F03Prik93zi jXQ0MuoExuirfsSiR6of0Bk9z+685/GYw7SQfZM6cmnzFjt5VEKxkRk7kRUUHQRP6W sAntpAAf820X/JJyE8N0YeshMzhBqn5vqASJOvWRj679qL5D4SzO6V1RH4QTgrN9cT +VqLoqedq9CDw== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 20:33:03 +0200 X-ME-IP: 89.207.171.96 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 1/4] ACPI: sysfs: Fix the check for a potential string truncation Date: Mon, 23 Oct 2023 20:32:54 +0200 Message-Id: <20001867d5d19c3b3e677f6020750cc232b3325b.1698081019.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 11:33:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780572227513966850 X-GMAIL-MSGID: 1780572227513966850 snprintf() does not return negative values on error. To know if the buffer was too small, the returned value should be compared with the length of the passed buffer. If it is bigger or equal, then the output has been truncated. Update the test for truncation accordingly. Also return -ENOMEM in such a case, as already done below in the same functions. Fixes: 8765c5ba1949 ("ACPI / scan: Rework modalias creation when "compatible" is present") Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 9d8e90744cb5..4deb36dccb73 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -158,8 +158,8 @@ static int create_pnp_modalias(const struct acpi_device *acpi_dev, char *modalia return 0; len = snprintf(modalias, size, "acpi:"); - if (len <= 0) - return len; + if (len >= size) + return -ENOMEM; size -= len; @@ -212,8 +212,8 @@ static int create_of_modalias(const struct acpi_device *acpi_dev, char *modalias len = snprintf(modalias, size, "of:N%sT", (char *)buf.pointer); ACPI_FREE(buf.pointer); - if (len <= 0) - return len; + if (len >= size) + return -ENOMEM; of_compatible = acpi_dev->data.of_compatible; if (of_compatible->type == ACPI_TYPE_PACKAGE) { From patchwork Mon Oct 23 19:33:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 157074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1509662vqx; Mon, 23 Oct 2023 12:33:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaBsXFN3MB8iX5VmIlYkVx+7/9C4oYAh3OdS5uERFwwlxXJC9kHJSv07Rp5Dld+ARX766h X-Received: by 2002:a05:6359:6e15:b0:168:e599:cfee with SMTP id th21-20020a0563596e1500b00168e599cfeemr2043855rwb.9.1698089624330; Mon, 23 Oct 2023 12:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698089624; cv=none; d=google.com; s=arc-20160816; b=kY3OThonvICvw48O9galQiQKpLvrt0vtMoOkWxVGfU94GCf15e7Bk22ms132GoSNkD ABnBS5zX/3ACe5w3+9ONKlgEYzw3BNcUHlz/tEdOs7J3erJHlTAQJpyR8TvUyKh8Iv8E u86CXwdZZH5mVencdIByOX8CqnoUcOh+z4S56LdB8e2BIs4vqhSUAzT4u0cdRcGD6rh1 m/bG4bjh5gbMxZ52I81ITPTwiRQqpgUrG6vATdipaKKci6D8V92iCEmPLK0wt/Ei3tHb MjFTjdY5DA7foOVhpJq6WlJURv0vulrEWQ2J92eA1sGHB2i+88NX5IhR4eqLSPfdb2W8 4uBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MlLlyO5nmPmV+Of5dabISHH05s0yAgNbg1lqfnhBiDo=; fh=BqhVhkt11hdmkbujRH8QIfD2cez9lYpeRoddPZBJma8=; b=0HLtiKPXAsxeKniR29sbHut64o/lXoreLVZddFZG0Z8baEKh2iZ8DXqIfWH7Mctzxc 34XldrARIlhejrI+jCJQ4Z3iAtnGjrOpOYwLH3niWvDid+iHI4S8FJbfln5OYg8WI9+Z ctaxD/FLPj5ycvWP+BGdzmnSJaJRa8PD12vcxe+fp6YEPaUHlKEbM9hIPcCLKqC5jV9O UZXJ/OY4rGv3SbLqnwrzJVzIad08XY16auPWLBq3axXKUkyTUknUOAHaaQUetSOVA0CR ROOliv1s44cEmFGtPzktWiYsX3UzMuNqB1QzrgGCoox44zc/XqKzosudIRxHE8usgLGm LFJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=migciIyc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id 20-20020a630114000000b005aa0e024d60si6732593pgb.25.2023.10.23.12.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 12:33:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=migciIyc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E9CCA8032A37; Mon, 23 Oct 2023 12:33:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjJWTda (ORCPT + 27 others); Mon, 23 Oct 2023 15:33:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjJWTd3 (ORCPT ); Mon, 23 Oct 2023 15:33:29 -0400 Received: from smtp.smtpout.orange.fr (smtp-24.smtpout.orange.fr [80.12.242.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CB11B4 for ; Mon, 23 Oct 2023 12:33:26 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPSA id v0fzqGEQclciav0fzqWHCB; Mon, 23 Oct 2023 21:33:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698089604; bh=MlLlyO5nmPmV+Of5dabISHH05s0yAgNbg1lqfnhBiDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=migciIycEHHxVSLdlbD0OWW2VjQcd388g4a4U6rPubKQtgb7HRtjFpJ689ZOdUYfJ M4DjVn6rYm2JxOdyf/1Iv8L43HNqSsvwlKONI+C/7GXglHEqf3PJXDuA3QavdkyrQe p0Ub2Cah2/euUBdqZnOBr/06U7KJDK+7wDHYJSYKqMN/EVMycRrdJPzEBvRfg6sLz0 ToJ4IBNGuk04t0PpFcPhck9S0I+d+73KNfWr+J7PcswUyNqVpMLLYXM5F9DJ9f2cL/ ud6XVZF0TjAnFY3ldTZLfVSVJjXUzRrKUTjGqr+mM6UaMwgZKN2dc0NXOComv7RoB8 kDofSZJzzAWWg== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 21:33:24 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/4] ACPI: sysfs: Fix a potential out-of-bound write in create_of_modalias() Date: Mon, 23 Oct 2023 21:33:16 +0200 Message-Id: <004a9aa85dcc37d112443e133c9edfd7624cd47b.1698081019.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 12:33:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780576026159462496 X-GMAIL-MSGID: 1780576026159462496 The remaining size of the buffer used by snprintf() is not updated after the first write, so subsequent write in the 'for' loop a few lines below can write some data past the end of the 'modalias' buffer. Correctly update the remaining size. Note that this pattern is already correctly written in create_pnp_modalias(). Fixes: 8765c5ba1949 ("ACPI / scan: Rework modalias creation when "compatible" is present") Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 4deb36dccb73..7ec3142f3eda 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -215,6 +215,8 @@ static int create_of_modalias(const struct acpi_device *acpi_dev, char *modalias if (len >= size) return -ENOMEM; + size -= len; + of_compatible = acpi_dev->data.of_compatible; if (of_compatible->type == ACPI_TYPE_PACKAGE) { nval = of_compatible->package.count; From patchwork Mon Oct 23 19:33:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 157075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1509718vqx; Mon, 23 Oct 2023 12:33:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFyxSaiw4dREmdmp4Y7QqokF6xpKA7KNi9YvsrI7D9/nL/VWZqvhVgxwVRp1nDeL8Crp24V X-Received: by 2002:a62:b610:0:b0:68a:6d34:474b with SMTP id j16-20020a62b610000000b0068a6d34474bmr15155661pff.15.1698089630195; Mon, 23 Oct 2023 12:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698089630; cv=none; d=google.com; s=arc-20160816; b=UpqLKrHdtdPVCoF+mIY1kCtf6kZAttcMfo3mZ2CaUeNhG9zMukcP3+8B1ZI/SWZRgo dx74An1muZ/Zhi6YFuv2owA07PosMP1FAhdyXfwBHFXmnzwu5lfwxW4YH4/HFO/MPBk6 EcCMExgCI5lKYkviUMpxjJnmqUeqUCW0rxcwrYS0rbpvwaMvYh5CB66QTlcw04JGHR/x +tNhrruq9QBUqtGdoBiuBIVnLKp9FMHDqi8QESsykXIPsM7rNE7QRsuGyHNXECl4tni4 /WnkgcttkJ9Ic+bpAAZYOzWXd1t3VKRq64eRSuqIAl+rnZ9khBlXhrAxmjWuIHpLrFVt /RHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/5Qo3nS8waaAiEey/mOoHQa+DwKTxtDvbnHYmE4+GsM=; fh=BqhVhkt11hdmkbujRH8QIfD2cez9lYpeRoddPZBJma8=; b=LeE1ezREIwVljikZYhV4n8J0pSDpzOoJvDtJwX++oJWTJe/ez/BmC/louSwZaXUBCu 1Qqc0lRYv1mCi6HQP+RWPp2/lS9aFfSGuRwMm29dmoU4e7LawJ744ua8tmWChd+2FGK+ 1DYcet4SInvfJBkjUq8SGZQU6zM5bfOKyCdTps3zKKMatKrPHxdgof7gMCeYmILpqcg9 L/rZCXHu7dWXdJ6+ygKM5J7YQhYxrpN+vvMO/o0uTjIBTe4fNGX/zv937ICCXpONoF44 qSCx/i072ZE8iKrq3KWIhp8vXD2Cc891o/zAPFOvNy/iLzRxglHhJY4GiQKHTuqVrziB g7iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="iP/bKu14"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id d22-20020aa797b6000000b0068fe12b361dsi6698162pfq.249.2023.10.23.12.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 12:33:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="iP/bKu14"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E6726809B0BB; Mon, 23 Oct 2023 12:33:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbjJWTdc (ORCPT + 27 others); Mon, 23 Oct 2023 15:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjJWTdb (ORCPT ); Mon, 23 Oct 2023 15:33:31 -0400 Received: from smtp.smtpout.orange.fr (smtp-23.smtpout.orange.fr [80.12.242.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FFA2B4 for ; Mon, 23 Oct 2023 12:33:29 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPSA id v0fzqGEQclciav0g4qWHEJ; Mon, 23 Oct 2023 21:33:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698089608; bh=/5Qo3nS8waaAiEey/mOoHQa+DwKTxtDvbnHYmE4+GsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iP/bKu14gUhGjswtz4l38t2ht/2Tcp77Pltkl5s8fh2CbTDC3k+5SxHNQw8oSj4Q0 ImbJS7ubWWo7ZyBd+EbHnjPYcHXocTMqD42S7miGBjMv85zuknLVGSZnuFs6t+H2G+ 5aAp6lTX+7wPIfLmMt4BH3FtovjY8jktzW2yihDchkpC9t2APtudx3rPK6XLxjQ4dP 052FHs+M3uNsazOSc2hEUNk7eJ01TjzZzzwSOm9Smj/OiKPkfyTMaswnvIV+z9nHWM k26E1DIo/DfM6JyJA9UtjIDmz+9HCOnKgUvpbTwiW56ITasuxPVxfBwREJmtOE7aNh GyTo42AJXguFw== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 21:33:28 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 3/4] ACPI: sysfs: Remove some useless trailing NULL writes Date: Mon, 23 Oct 2023 21:33:17 +0200 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 23 Oct 2023 12:33:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780576031897986852 X-GMAIL-MSGID: 1780576031897986852 'modalias' is only written with snprintf(), so it is already guaranteed to be NULL terminated. Remove the unneeded (but harmless) writes of a trailing '\0'. Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 7ec3142f3eda..1cf6568a813f 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -177,7 +177,7 @@ static int create_pnp_modalias(const struct acpi_device *acpi_dev, char *modalia len += count; size -= count; } - modalias[len] = '\0'; + return len; } @@ -237,7 +237,7 @@ static int create_of_modalias(const struct acpi_device *acpi_dev, char *modalias len += count; size -= count; } - modalias[len] = '\0'; + return len; } From patchwork Mon Oct 23 19:33:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 157076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1509719vqx; Mon, 23 Oct 2023 12:33:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQQ7w0SBloL+ipvZd/jerrYox8r9hyYdwrkfcmxHfsSZmMVyqMT/N5AGKBoWy77TCtc4rv X-Received: by 2002:a17:902:e54e:b0:1c9:ddd8:9950 with SMTP id n14-20020a170902e54e00b001c9ddd89950mr13221438plf.21.1698089630363; Mon, 23 Oct 2023 12:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698089630; cv=none; d=google.com; s=arc-20160816; b=wVIYKlNG8CsgQF0MeU/ce5Xn62z4fURflS9Vjb+0I09fCg7Zp5qv4c0ygoEMSEOF1X rvGMBQp93hX6j6ziRbqnNe3cDbsBqd4YNXR/UxXbRf59jWIoakaz+K2vliqSliAjTQaF gIetD3myLvQC+qzaORJVGs05SCyXk6s6ef/9Y4lE+DtpMUvH2cuhjqMvhjn/Eh9Y25uP 2GfYMVjv0/xxoxMtZuH/G49+9ayEsC1XwuyDre2z8q6I3yRZNUpGmGvX+zgngJC0z1eX iBEct7JAz8orJUB4GZ7E4dhlhjfkFdHgyzVvJ2f4XNLqbp3xX1Q1lYcC/cdYOZZWZL+1 k36A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kOczc4xzag/NnlA9XkZf9hv4EVckr0nepjgeN8+fjfE=; fh=BqhVhkt11hdmkbujRH8QIfD2cez9lYpeRoddPZBJma8=; b=PiF3cXVANaNEQ3VvMM7hNCJY7q7y5wVcKhOb6BP/YJWXHQbs03SAGpSd8Dnc5DavAO kk09FuH2CoBkpobA5W8WlRMV0jfbnjQP+gHGbFHnvYmEqdhbsuHXc+8KBV+VDkV8NbuB 8my31swFXwAf0g35TB0rMIhBdGRFMNDJZLJlMyp6QE37MQNueBi++7VIh2VoMkiuzmoM l5dV9AbiQoMPiQjseB5dpjVl0jrHbL4+749Ly5K/35iV7CCRP3g3d8ZawqRvq3c8s6w0 urw0eF9fSR+UVXTq9eV+8nYfCyhYZiZXBQZrZMhcJvKw45lYu43Wns7tHEQlnOgSKDBb YMkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=R+rP9eZt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id s17-20020a170902a51100b001c9f54d26bfsi6665600plq.516.2023.10.23.12.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 12:33:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=R+rP9eZt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3F8D4807C563; Mon, 23 Oct 2023 12:33:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbjJWTde (ORCPT + 27 others); Mon, 23 Oct 2023 15:33:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbjJWTdd (ORCPT ); Mon, 23 Oct 2023 15:33:33 -0400 Received: from smtp.smtpout.orange.fr (smtp-24.smtpout.orange.fr [80.12.242.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 712E694 for ; Mon, 23 Oct 2023 12:33:31 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPSA id v0fzqGEQclciav0g5qWHER; Mon, 23 Oct 2023 21:33:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698089610; bh=kOczc4xzag/NnlA9XkZf9hv4EVckr0nepjgeN8+fjfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=R+rP9eZtOV0Gu0NgUyXgpD5G0f7Mtnczfb9ANQB6jCAf4xSPtHm9RgbLkUnE2KTiG bMzIpIpSvRY8aVNbezdI543C0GvzU2WBn/AWvO8yTCymF+IEThHhmXyh6W2hnYgjih 47nmsTCLNMt1SjjO/t++jo/H/DcBtu2tBh45kl+XeeoQpwnjyNt3woqlqbN//11jK6 CtGtMniOzX2+jIp2J6vd40m9penXIjlljjSx21ozWTrFgNdliWCUSKO7hP1+Or8TDU LKjitwJAjSQjTlfkrtnqGvNXfrsVHmTIUD5mWrnIkAGnvWaMQn4dhqj183ecjJOEyL /8FbvSHUFvyOQ== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Mon, 23 Oct 2023 21:33:30 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 4/4] ACPI: sysfs: Remove some dead code Date: Mon, 23 Oct 2023 21:33:18 +0200 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 12:33:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780576032503485857 X-GMAIL-MSGID: 1780576032503485857 snprintf() never returns <0 values. So remove some dead code. Signed-off-by: Christophe JAILLET --- drivers/acpi/device_sysfs.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c index 1cf6568a813f..23373faa35ec 100644 --- a/drivers/acpi/device_sysfs.c +++ b/drivers/acpi/device_sysfs.c @@ -168,8 +168,6 @@ static int create_pnp_modalias(const struct acpi_device *acpi_dev, char *modalia continue; count = snprintf(&modalias[len], size, "%s:", id->id); - if (count < 0) - return -EINVAL; if (count >= size) return -ENOMEM; @@ -228,8 +226,6 @@ static int create_of_modalias(const struct acpi_device *acpi_dev, char *modalias for (i = 0; i < nval; i++, obj++) { count = snprintf(&modalias[len], size, "C%s", obj->string.pointer); - if (count < 0) - return -EINVAL; if (count >= size) return -ENOMEM;