Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2279864rwd; Fri, 16 Jun 2023 01:33:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4sXMgTFadj9Qv9tJSHJLTbgRlWR/WQa74VZxjuBaNpxKaJ5IdqlDrPZrxnq29EOb2vR356 X-Received: by 2002:a17:90a:1a51:b0:25b:a15e:58b8 with SMTP id 17-20020a17090a1a5100b0025ba15e58b8mr1841887pjl.10.1686904438126; Fri, 16 Jun 2023 01:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686904438; cv=none; d=google.com; s=arc-20160816; b=WymQb/M4oVOxstxZxlRNxzkJIWxZDDaygZyR5ZvUczRNZin/zvkBIJQw+mEAQ+s2BU /EZVyFqiJFeugFC0QJPAbweTmNsruRuyzwIaZKgH2MJyoPt02u6y9JAS+a7RguwoQYsJ tZp+OB+vYVMXIhx4cvtNYqreJ1k50r/wIy1LiKBphygP2nY82HZatEOpXEsKEuuURmzc 6Qi0EyLDWlvLlHxwGMxuFwoAIV/7LskKz65Z6jwcEZ/+tUBrs7+E7bnMI8H1Pq9gHb7R XskzO3iakSL4O9RrjGXJWwXlvFYP+9RRPTStgU7cv14arKSTSiy3qLkiPBWTnRbMv0aN bNQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=Hwv94yi8Ao4nPDhfan026IGHqcrsNc0tVXsG2uPDm+s=; b=YXj/im5fQOFIrLwKXVQI5XEX4FQE44TnvVE3rUyrpb5kLgt1j2MjwXoBHegZSgYgx0 tezz0jKssJ25Vht1UqzoC2bY4zJe67a5OceXvqKgEcbtSBp7MidSnbg1pLolDOGFHbhi 8hfecwTq4Lv+gnt79OoFSuwtHXgxAeOx9EO+vDaiw8+cgBNcX6XGEkFBNR2jtYei/sFZ 0mKhYxxI6EjCT/fRkSzQUu+IX7/+0ibQTh3BeFI+qRC17FHJkxz8X7Gw+BixK88S1C2y KchGCwjBVJ8jA/qzVYgLSWh5nKdk3g7U5SIICDmpu76izkHAgLBrqGw5n4DD/B0VYj01 wcWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a637506000000b0051322a8d2aesi2316707pgc.110.2023.06.16.01.33.46; Fri, 16 Jun 2023 01:33:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243792AbjFPIBq convert rfc822-to-8bit (ORCPT + 99 others); Fri, 16 Jun 2023 04:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242189AbjFPIBo (ORCPT ); Fri, 16 Jun 2023 04:01:44 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 825BA2945 for ; Fri, 16 Jun 2023 01:01:42 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-12-wR-rwUJuOZepVZfHZ7CX4A-1; Fri, 16 Jun 2023 09:01:38 +0100 X-MC-Unique: wR-rwUJuOZepVZfHZ7CX4A-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 16 Jun 2023 09:01:35 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 16 Jun 2023 09:01:35 +0100 From: David Laight To: "'wuyonggang001@208suo.com'" , "jejb@linux.ibm.com" , "martin.petersen@oracle.com" CC: "linux-scsi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "hare@kernel.org" Subject: RE: [PATCH] scsi: myrs: Replacing snprintf with scnprintf Thread-Topic: [PATCH] scsi: myrs: Replacing snprintf with scnprintf Thread-Index: AQHZnoT513c9A1R2cUiaoES5niWIb6+NEQBg Date: Fri, 16 Jun 2023 08:01:35 +0000 Message-ID: <688a2c10bdd24db8a4bf86effdb52606@AcuMS.aculab.com> References: <20230613065350.39003-1-zhanglibing@cdjrlc.com> <6d2c37de23facd0cd854bbaf6913ba3e@208suo.com> In-Reply-To: <6d2c37de23facd0cd854bbaf6913ba3e@208suo.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: wuyonggang001@208suo.com > Sent: 14 June 2023 06:56 > > Fix the following coccicheck warning: > > drivers/scsi/myrs.c:1411:8-16: WARNING: use scnprintf or sprintf That is nothing like the world best commit message. Also if any of the snprintf() actually overflow the terminating '\n' is lost - that will have unexpected effects over and above the truncation. In fact all the buffer sizes are bogus - did you even look at the code. I think they should all be using sysfs_emit(). There is also this one: char serial[17]; memcpy(serial, cs->ctlr_info->serial_number, 16); serial[16] = '\0'; return snprintf(buf, 16, "%s\n", serial); A "%.16s\n" format will have the desired effect. But completely untested with long names because the 16 isn't big enough. David > > Signed-off-by: Yonggang Wu > --- > drivers/scsi/myrs.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c > index a1eec65a9713..ced1d2fbd862 100644 > --- a/drivers/scsi/myrs.c > +++ b/drivers/scsi/myrs.c > @@ -939,7 +939,7 @@ static ssize_t raid_state_show(struct device *dev, > int ret; > > if (!sdev->hostdata) > - return snprintf(buf, 16, "Unknown\n"); > + return scnprintf(buf, 16, "Unknown\n"); > > if (sdev->channel >= cs->ctlr_info->physchan_present) { > struct myrs_ldev_info *ldev_info = sdev->hostdata; > @@ -1058,7 +1058,7 @@ static ssize_t raid_level_show(struct device *dev, > const char *name = NULL; > > if (!sdev->hostdata) > - return snprintf(buf, 16, "Unknown\n"); > + return scnprintf(buf, 16, "Unknown\n"); > > if (sdev->channel >= cs->ctlr_info->physchan_present) { > struct myrs_ldev_info *ldev_info; > @@ -1086,7 +1086,7 @@ static ssize_t rebuild_show(struct device *dev, > unsigned char status; > > if (sdev->channel < cs->ctlr_info->physchan_present) > - return snprintf(buf, 32, "physical device - not rebuilding\n"); > + return scnprintf(buf, 32, "physical device - not > rebuilding\n"); > > ldev_info = sdev->hostdata; > ldev_num = ldev_info->ldev_num; > @@ -1190,7 +1190,7 @@ static ssize_t consistency_check_show(struct > device *dev, > unsigned short ldev_num; > > if (sdev->channel < cs->ctlr_info->physchan_present) > - return snprintf(buf, 32, "physical device - not checking\n"); > + return scnprintf(buf, 32, "physical device - not checking\n"); > > ldev_info = sdev->hostdata; > if (!ldev_info) > @@ -1303,7 +1303,7 @@ static ssize_t serial_show(struct device *dev, > > memcpy(serial, cs->ctlr_info->serial_number, 16); > serial[16] = '\0'; > - return snprintf(buf, 16, "%s\n", serial); > + return scnprintf(buf, 16, "%s\n", serial); > } > static DEVICE_ATTR_RO(serial); > > @@ -1313,7 +1313,7 @@ static ssize_t ctlr_num_show(struct device *dev, > struct Scsi_Host *shost = class_to_shost(dev); > struct myrs_hba *cs = shost_priv(shost); > > - return snprintf(buf, 20, "%d\n", cs->host->host_no); > + return scnprintf(buf, 20, "%d\n", cs->host->host_no); > } > static DEVICE_ATTR_RO(ctlr_num); > > @@ -1388,7 +1388,7 @@ static ssize_t model_show(struct device *dev, > struct Scsi_Host *shost = class_to_shost(dev); > struct myrs_hba *cs = shost_priv(shost); > > - return snprintf(buf, 28, "%s\n", cs->model_name); > + return scnprintf(buf, 28, "%s\n", cs->model_name); > } > static DEVICE_ATTR_RO(model); > > @@ -1398,7 +1398,7 @@ static ssize_t ctlr_type_show(struct device *dev, > struct Scsi_Host *shost = class_to_shost(dev); > struct myrs_hba *cs = shost_priv(shost); > > - return snprintf(buf, 4, "%d\n", cs->ctlr_info->ctlr_type); > + return scnprintf(buf, 4, "%d\n", cs->ctlr_info->ctlr_type); > } > static DEVICE_ATTR_RO(ctlr_type); > > @@ -1408,7 +1408,7 @@ static ssize_t cache_size_show(struct device *dev, > struct Scsi_Host *shost = class_to_shost(dev); > struct myrs_hba *cs = shost_priv(shost); > > - return snprintf(buf, 8, "%d MB\n", cs->ctlr_info->cache_size_mb); > + return scnprintf(buf, 8, "%d MB\n", cs->ctlr_info->cache_size_mb); > } > static DEVICE_ATTR_RO(cache_size); > > @@ -1418,7 +1418,7 @@ static ssize_t firmware_show(struct device *dev, > struct Scsi_Host *shost = class_to_shost(dev); > struct myrs_hba *cs = shost_priv(shost); > > - return snprintf(buf, 16, "%d.%02d-%02d\n", > + return scnprintf(buf, 16, "%d.%02d-%02d\n", > cs->ctlr_info->fw_major_version, > cs->ctlr_info->fw_minor_version, > cs->ctlr_info->fw_turn_number); > @@ -1488,7 +1488,7 @@ static ssize_t > disable_enclosure_messages_show(struct device *dev, > struct Scsi_Host *shost = class_to_shost(dev); > struct myrs_hba *cs = shost_priv(shost); > > - return snprintf(buf, 3, "%d\n", cs->disable_enc_msg); > + return scnprintf(buf, 3, "%d\n", cs->disable_enc_msg); > } > > static ssize_t disable_enclosure_messages_store(struct device *dev, - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)