From patchwork Mon Mar 12 12:48:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salvatore Mesoraca X-Patchwork-Id: 10276187 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 10D70601A0 for ; Mon, 12 Mar 2018 12:51:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0188128E90 for ; Mon, 12 Mar 2018 12:51:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F073928E78; Mon, 12 Mar 2018 12:51:15 +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=-4.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id B1E7028E6A for ; Mon, 12 Mar 2018 12:50:43 +0000 (UTC) Received: (qmail 30508 invoked by uid 550); 12 Mar 2018 12:49:19 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 30440 invoked from network); 12 Mar 2018 12:49:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=MoiqE9ho08LAgmLjc7kM/OARU7Flf5Yw/ajGZERHywo=; b=Iync2BywEUcWvpaXijJVbOE4G/S292Am7o3gY8jlTPbEoRZpwjy0Pr+ufZh7golIeh JoaHeuPAcDNVQ1dyRLn2D06i3L4nV/0tgeDFIU6AhemuHUtfs5Ceh4oYH73kIM11CRjB h63vrm+25hfK3GSPB9hhmlcVSBeiQfs5N0bltjKx7YkyswIgNHJlcO7I9Ki2RWCO0yV7 g2tr+SF++yOL/8KRXZ2T1dyQ5NenYs76gxY8U3S1Q4YfJ3o8bjBZLbHJkrVbQ+5v0nsp uKLzZ9fVooE/MxkiDawBSWQfdwk677M6KX2bpq8zu+cm2DLaCtqKCBnK813DaX9/96yg o3pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MoiqE9ho08LAgmLjc7kM/OARU7Flf5Yw/ajGZERHywo=; b=iMCLqlYDsZjyrodUcYcQy61xaH5QKO5EJun5cNrhJbmsXw6hlSdAE6wx9J2ut5jSqP Q1YPlFw9W5k2xKHqote3uyZ9VztVDvLAe9VPxMqUIpmqqgBT2F+/eOuuWzaVbW9qAT/b 2h22SU2pH2HFQaYD6seKEe3z+DMVEPkegNNmPp4EiiCcUfdIhj0VlYFpFbKGYCsq3Ler l6TP+Hk0NacXTyedg1/90x65zB2u2TP3Bss6hS2WrbMbMgi9VxeaqPaUdb6aSUWblhiJ uN9ZIkk2QESNLUOxBrXRwE2AcOWjgo4AI9DaQK2VvxzQy8Ff+tyjcnONRNj+eiErm7gg 6TiA== X-Gm-Message-State: AElRT7EIh7bOutAg7jSJJGw7+L8WGBl2+OupfaHvTIFtCd/J6r64k5hI zN2WUvVYjIKaU4JBRtbWnI4= X-Google-Smtp-Source: AG47ELv+hLLFC1PRoorfB8025gL6L7a9gw9fHdG4OQTDoySqn+iprS5UTfPWJBfOjiHKGmSrXq2QXA== X-Received: by 10.223.135.237 with SMTP id c42mr473187wrc.146.1520858947369; Mon, 12 Mar 2018 05:49:07 -0700 (PDT) From: Salvatore Mesoraca To: linux-kernel@vger.kernel.org Cc: kernel-hardening@lists.openwall.com, linux-scsi@vger.kernel.org, "James E.J. Bottomley" , "Martin K. Petersen" , "Tobin C. Harding" , Dario Ballabio , Kees Cook , Salvatore Mesoraca , valdis.kletnieks@vt.edu Subject: [PATCH v2] scsi: eata: drop VLA in reorder() Date: Mon, 12 Mar 2018 13:48:57 +0100 Message-Id: <1520858937-3582-1-git-send-email-s.mesoraca16@gmail.com> X-Mailer: git-send-email 1.9.1 X-Virus-Scanned: ClamAV using ClamSMTP Avoid 3 VLAs[1] by using a single dinamically allocated array and some helper variables: we don't need 3 arrays. [1] https://lkml.org/lkml/2018/3/7/621 Signed-off-by: Salvatore Mesoraca --- drivers/scsi/eata.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c index 6501c33..8ba44b7 100644 --- a/drivers/scsi/eata.c +++ b/drivers/scsi/eata.c @@ -2091,12 +2091,14 @@ static void sort(unsigned long sk[], unsigned int da[], unsigned int n, static int reorder(struct hostdata *ha, unsigned long cursec, unsigned int ihdlr, unsigned int il[], unsigned int n_ready) { + int overlap; struct scsi_cmnd *SCpnt; struct mscp *cpp; unsigned int k, n; unsigned int rev = 0, s = 1, r = 1; - unsigned int input_only = 1, overlap = 0; - unsigned long sl[n_ready], pl[n_ready], ll[n_ready]; + unsigned int input_only = 1; + unsigned long *sl; + unsigned long sl_zero, sl_cur, sl_prev, ll_cur, ll_prev; unsigned long maxsec = 0, minsec = ULONG_MAX, seek = 0, iseek = 0; unsigned long ioseek = 0; @@ -2115,6 +2117,12 @@ static int reorder(struct hostdata *ha, unsigned long cursec, if (n_ready <= 1) return 0; + overlap = -ENOMEM; + sl = kcalloc(n_ready, sizeof(*sl), GFP_ATOMIC); + if (!sl) + goto out; + overlap = 0; + for (n = 0; n < n_ready; n++) { k = il[n]; cpp = &ha->cp[k]; @@ -2164,31 +2172,33 @@ static int reorder(struct hostdata *ha, unsigned long cursec, if (!((rev && r) || (!rev && s))) sort(sl, il, n_ready, rev); + sl_zero = sl[0]; + if (!input_only) for (n = 0; n < n_ready; n++) { k = il[n]; cpp = &ha->cp[k]; SCpnt = cpp->SCpnt; - ll[n] = blk_rq_sectors(SCpnt->request); - pl[n] = SCpnt->serial_number; + ll_cur = blk_rq_sectors(SCpnt->request); + sl_cur = sl[n]; + sl[n] = SCpnt->serial_number; - if (!n) - continue; - - if ((sl[n] == sl[n - 1]) - || (!rev && ((sl[n - 1] + ll[n - 1]) > sl[n])) - || (rev && ((sl[n] + ll[n]) > sl[n - 1]))) + if (n && ((sl_cur == sl_prev) + || (!rev && ((sl_prev + ll_prev) > sl_cur)) + || (rev && ((sl_cur + ll_cur) > sl_prev)))) overlap = 1; + ll_prev = ll_cur; + sl_prev = sl_cur; } if (overlap) - sort(pl, il, n_ready, 0); + sort(sl, il, n_ready, 0); if (link_statistics) { - if (cursec > sl[0]) - iseek = cursec - sl[0]; + if (cursec > sl_zero) + iseek = cursec - sl_zero; else - iseek = sl[0] - cursec; + iseek = sl_zero - cursec; batchcount++; readycount += n_ready; seeknosort += seek / 1024; @@ -2225,6 +2235,8 @@ static int reorder(struct hostdata *ha, unsigned long cursec, YESNO(overlap), cpp->din); } #endif + kfree(sl); +out: return overlap; }