From patchwork Tue Feb 20 09:45:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10229647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7F979602B1 for ; Tue, 20 Feb 2018 09:45:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6969E285C9 for ; Tue, 20 Feb 2018 09:45:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D921285CC; Tue, 20 Feb 2018 09:45:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDA76285C9 for ; Tue, 20 Feb 2018 09:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751043AbeBTJpr (ORCPT ); Tue, 20 Feb 2018 04:45:47 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:42700 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750871AbeBTJpp (ORCPT ); Tue, 20 Feb 2018 04:45:45 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1K9g5xM139265; Tue, 20 Feb 2018 09:45:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2017-10-26; bh=NzjkseKy3sNrOX1ev/yeE+9NQnmdG/Lxt3da1cPtFeQ=; b=JcP4UdxTDAEwi7mwJ0eGrqjFVOSYYK14MRQSJ9Pgbx2a+RpdweYAAl4+xJvrrJct5bHK s+/KAPPLqPjy4qnGJ3bhcEhwjF09+vux9vflHAZkQ8gRXHgSeMzwSkl1n8GTcAI24rBF zIt0BOzcgy1BWMMaGU5uSD0nNF2DzpxrCP60Pji0nsBJ0RR3tOMqfrWHJYkjE5w1k0V3 7896JOtLQdXuIKbrsfgnuUKLIjjo4mkjGCzzkaE+02m8iWbdGs/69agyQ0n4WSowrTJv U7+zOzw91CaS7JHw1IoQRTr25kBdA3nD/FEJDR890h+waSZbjWx0cpJUIcX5mN+Knmp2 9w== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2g8h56g3pq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Feb 2018 09:45:43 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w1K9jhLq002318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 20 Feb 2018 09:45:43 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w1K9jg1Q007920; Tue, 20 Feb 2018 09:45:42 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Feb 2018 01:45:42 -0800 Date: Tue, 20 Feb 2018 12:45:35 +0300 From: Dan Carpenter To: "James E.J. Bottomley" Cc: "Martin K. Petersen" , linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/2] scsi: myrs: cleanup myrs_store_suppress_enclosure_messages() Message-ID: <20180220094535.GA22646@mwanda> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.9.3 (2018-01-21) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8809 signatures=668674 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=958 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802200126 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This code causes a static checker because we have an upper bound on "value" but not a lower bound. In other words "value" can be s32min-2. It's harmless but really it should just be bool. Signed-off-by: Dan Carpenter diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c index 3b87c6942a8e..eaa9d143a282 100644 --- a/drivers/scsi/myrs.c +++ b/drivers/scsi/myrs.c @@ -1590,15 +1590,12 @@ static ssize_t myrs_store_suppress_enclosure_messages(struct device *dev, { struct scsi_device *sdev = to_scsi_device(dev); myrs_hba *cs = (myrs_hba *)sdev->host->hostdata; - char tmpbuf[8]; - ssize_t len; - int value; + bool value; + int ret; - len = count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; - strncpy(tmpbuf, buf, len); - tmpbuf[len] = '\0'; - if (sscanf(tmpbuf, "%d", &value) != 1 || value > 2) - return -EINVAL; + ret = kstrtobool(buf, &value); + if (ret) + return ret; cs->disable_enc_msg = value; return count;