Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp130003rdb; Thu, 8 Feb 2024 00:50:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWsJHOjvWEuC7ky+QGPEN/PrQuA2eJpyNn3WJ1ExzkJVG+ELq8bWcVcDIRj3j2RAzGkuE7 X-Received: by 2002:a05:6870:1cb:b0:214:2e69:c04a with SMTP id n11-20020a05687001cb00b002142e69c04amr9253636oad.22.1707382223838; Thu, 08 Feb 2024 00:50:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707382223; cv=pass; d=google.com; s=arc-20160816; b=I4OQGmwRFh6UID/UwWxlMmFu6f5090O0+Jo+NwjpbFw7Wh3QXcqg1wrZBFYaguBv1L avJKSz25jk3+OJsxJ2W82Fny/38M8VbP2/XJYtBpMr98rA4MGe5g+FT5HrpR7bd6Db0u mx5y8a2kM/iDafACeQH2wde/R6G+VlUoinLSM9IdgBH7ndksypFi6Z4uZDmWCwdBOmat MEJUA64bEkNZ4w5HdlD0CcEC7fd8kuPwIRUZ8c2yZ6Gnz21dhysACOdZJEKjb1629Fij 70pRnP+VGlKGqBWsuR5SUzQ6HqpwwAxbLSmY5D4oNwBtnU+FAOFs0Tvlouug0G8bmXZJ WZ1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kKDoKRMxVZ3NchU/uxigCs7qj01UcQxlRGmJ/+pW4GU=; fh=IWGl+EoZB9GgvX4CcMrhtTYNbl22C5J2NdEKe4N9g98=; b=uMQ5eAwQvd+oSl8lNajbamiyvD1n6p4xEwl8QDHWKOLeM88maygUKMq5x8ZrQllmTk V3PUYlx8hH8jNxnwN0IXsNgoU5fuyFDJHXjXFlQhpQgYO7bBvMtxndFTgP8r6nPPaeCJ SIRGMyZpaXnrG6kEsQEp33+fHABMT56liYE/At/VWjslZCho3sdh0oE3bTiyGwdP6wUB bjPOv483b5IhoacW2B4Z+uzLR5Lt6Ul0sntOYrTSspVHoFNpBEaPdtp9KCQSLAIZC7UU nsgjyjIdiGGjncqBz6neSKW9S9leFq0LqTGK+RZqVNX8uS9M4X40D7cWZJBvoe/kYxBw 41lQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J+AyC1IJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57655-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57655-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXG0q1PhBOn0yW5+BzkE1huWyKol9iY/kNXka5VIAHnPqN05zhfgx1RySIY81khgVuqp4Uqj5bp42ltCRWKfA7oufuanlFXoOQGqPp2aw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f24-20020a637558000000b005cf5895bfa6si3449091pgn.814.2024.02.08.00.50.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 00:50:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57655-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J+AyC1IJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57655-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57655-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3A6CC2834C9 for ; Thu, 8 Feb 2024 08:50:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B8E976049; Thu, 8 Feb 2024 08:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J+AyC1IJ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 702AC76026; Thu, 8 Feb 2024 08:45:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381937; cv=none; b=hhjbRqxB40t4BvmfYSTN/D582LT6/uvh1HD7WeffP0D25EX09pQCL2JEtu1YJisjeBw0fqVKrmi0sdTUIvnFm0HlEkF796H/UA1n012sFuXhI5lqenfaZuBXuN39AhzFOVBBCiMb+tdjAP4Y5YL88fnK+peuEt8eDBoQ7135rTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707381937; c=relaxed/simple; bh=lMT5ds09tPKnvt5Z0XoIWL0MTp/63mQAtpaTLMS6Bp8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FvMA2J2qSZEdw0hZErbGteyrLrWJhalxQRYfJk6vLMB/tkvzTBTgddfdaBOeoH/wcJOfc+imY0JRhPeg8auWB2BclF9yYdK7Mp5N3R/fziVbzt2Mn1w16QwIv59GE2rcdFpaPLBvA037rIPF0vM0VZxqjZnIXc8IxjVibrYNB9c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J+AyC1IJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CEFEC43399; Thu, 8 Feb 2024 08:45:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707381937; bh=lMT5ds09tPKnvt5Z0XoIWL0MTp/63mQAtpaTLMS6Bp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J+AyC1IJGKuoOUKM5zUpx63JFqLmK3QCBMLMNCt2a87u7tEU2INr5mCviZhYP0aY4 jE+FZIXhMhOtL29JNAm/HuvP83u7gFMWthjuqXFRePQ2ccCLhWzb0P61wzQQGncLvY Wq+d7cvzmlMBf3QGUprdbxancpf64qlSJ+G+LbUosm8B8m6hhaqb0ZG2qC7L2uwgBa jRFgq2L8l84PNrXWXGck3eqqxs1MuTR8RRwAPmgdmAUOJIZzh8bixKKsR47yefhpKQ FS+pCBiRWxQMQxdOlSMZvgoXMhzs/81weorCR11zGzY79j2ctTvt+MoDfrj5gcDC09 +oCg4Lw/QFfYA== From: Lee Jones To: lee@kernel.org Cc: linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , John Garry , Luben Tuikov , linux-scsi@vger.kernel.org Subject: [PATCH 09/10] scsi: aic94xx: Remove snprintf() from sysfs call-backs and replace with sysfs_emit() Date: Thu, 8 Feb 2024 08:44:21 +0000 Message-ID: <20240208084512.3803250-10-lee@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240208084512.3803250-1-lee@kernel.org> References: <20240208084512.3803250-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Since snprintf() has the documented, but still rather strange trait of returning the length of the data that *would have been* written to the array if space were available, rather than the arguably more useful length of data *actually* written, it is usually considered wise to use something else instead in order to avoid confusion. In the case of sysfs call-backs, new wrappers exist that do just that. Link: https://lwn.net/Articles/69419/ Link: https://github.com/KSPP/linux/issues/105 Signed-off-by: Lee Jones --- Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: John Garry Cc: Luben Tuikov Cc: linux-scsi@vger.kernel.org --- drivers/scsi/aic94xx/aic94xx_init.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c index 8a3340d8d7ad4..c976e4b77c71e 100644 --- a/drivers/scsi/aic94xx/aic94xx_init.c +++ b/drivers/scsi/aic94xx/aic94xx_init.c @@ -264,8 +264,7 @@ static ssize_t asd_show_dev_rev(struct device *dev, struct device_attribute *attr, char *buf) { struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev); - return snprintf(buf, PAGE_SIZE, "%s\n", - asd_dev_rev[asd_ha->revision_id]); + return sysfs_emit(buf, "%s\n", asd_dev_rev[asd_ha->revision_id]); } static DEVICE_ATTR(aic_revision, S_IRUGO, asd_show_dev_rev, NULL); @@ -273,7 +272,7 @@ static ssize_t asd_show_dev_bios_build(struct device *dev, struct device_attribute *attr,char *buf) { struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev); - return snprintf(buf, PAGE_SIZE, "%d\n", asd_ha->hw_prof.bios.bld); + return sysfs_emit(buf, "%d\n", asd_ha->hw_prof.bios.bld); } static DEVICE_ATTR(bios_build, S_IRUGO, asd_show_dev_bios_build, NULL); @@ -281,7 +280,7 @@ static ssize_t asd_show_dev_pcba_sn(struct device *dev, struct device_attribute *attr, char *buf) { struct asd_ha_struct *asd_ha = dev_to_asd_ha(dev); - return snprintf(buf, PAGE_SIZE, "%s\n", asd_ha->hw_prof.pcba_sn); + return sysfs_emit(buf, "%s\n", asd_ha->hw_prof.pcba_sn); } static DEVICE_ATTR(pcba_sn, S_IRUGO, asd_show_dev_pcba_sn, NULL); @@ -452,7 +451,7 @@ static ssize_t asd_show_update_bios(struct device *dev, if (asd_ha->bios_status != FLASH_IN_PROGRESS) asd_ha->bios_status = FLASH_OK; - return snprintf(buf, PAGE_SIZE, "status=%x %s\n", + return sysfs_emit(buf, "status=%x %s\n", flash_error_table[i].err_code, flash_error_table[i].reason); } @@ -937,7 +936,7 @@ static int asd_scan_finished(struct Scsi_Host *shost, unsigned long time) static ssize_t version_show(struct device_driver *driver, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", ASD_DRIVER_VERSION); + return sysfs_emit(buf, "%s\n", ASD_DRIVER_VERSION); } static DRIVER_ATTR_RO(version); -- 2.43.0.594.gd9cf4e227d-goog