From patchwork Thu Feb 4 13:57:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 8221871 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6E45E9F37A for ; Thu, 4 Feb 2016 13:58:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 912E920394 for ; Thu, 4 Feb 2016 13:58:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B4471201EF for ; Thu, 4 Feb 2016 13:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752885AbcBDN6y (ORCPT ); Thu, 4 Feb 2016 08:58:54 -0500 Received: from mail-wm0-f43.google.com ([74.125.82.43]:33353 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965015AbcBDN6c (ORCPT ); Thu, 4 Feb 2016 08:58:32 -0500 Received: by mail-wm0-f43.google.com with SMTP id g62so5669346wme.0 for ; Thu, 04 Feb 2016 05:58:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AlsdkeObFExdr0DCz8EjrM0/ooccbX9UaUuEmtmNUHg=; b=Cp8uvxQz+9tY4IIp3YG/EDrawzFP/gLzR9CRU+pc4tPVyrSs4SX5aWeDtu5kCwG0x3 z/fsy20UKRV9Rt6YSVxKP6ttpOKhc/wpXeHyejZWEoDuMyh3f82fhdOAQYxK2rXEzgDP GUVCHnkd2EjO+EhcO4SXabsmEBWL3Rhg0KZKk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AlsdkeObFExdr0DCz8EjrM0/ooccbX9UaUuEmtmNUHg=; b=ZRzQyGCuxrH5/q6NmphjZJlg+JBiTjihazsk+En5CKqKPiJkZ+Nwoclq6+CbBUYg3n JN+gD2pYP+LersbTQMDeN+P2vfZ5N0S+I6yM2ICEGmhsvKku6jBiNblfFqSCX6hCMHrs 245SyyXajKhY+dvADilYbTxHZO2O4fjtR3WZSwcxooty8PduzWEQY5TuNJ3Zve2OrxJ9 ZxcafbGJzjg1TsIscNgrZzWdNRpza2MusLdSnGdy0gwsGgbW/iYjYMRbq/X4MOX56uYF nFhuz9berX648ejxN98KTBI/a62U5uuKXc6y8Hye9u+wjkv7HtaeTo4Jz/iS2Zo8MSVI dOrw== X-Gm-Message-State: AG10YOTlaFAPZv1aKZ47eiKBA70RYcYlgLKZVRisrDnficVxMFnvvU0txUyuR7BgkNQFKw== X-Received: by 10.195.11.226 with SMTP id el2mr9959955wjd.112.1454594311132; Thu, 04 Feb 2016 05:58:31 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id l194sm26656734wmb.14.2016.02.04.05.58.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Feb 2016 05:58:30 -0800 (PST) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@fb.com Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH 4/5] lightnvm: check overflow and correct mlc pairs Date: Thu, 4 Feb 2016 14:57:07 +0100 Message-Id: <1454594228-18970-5-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1454594228-18970-1-git-send-email-m@bjorling.me> References: <1454594228-18970-1-git-send-email-m@bjorling.me> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The specification currently limits the number of MLC pairs to 886. Make sure that a device is unable to be instantiate if more is configured. Also, previously the patch had the wrong math for copying MLC pairs, as it only copied half of the actual entries. Fixes: ca5927e7ab53 "lightnvm: introduce mlc lower page table mappings" --- drivers/nvme/host/lightnvm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c index 0f0864f..55dab93 100644 --- a/drivers/nvme/host/lightnvm.c +++ b/drivers/nvme/host/lightnvm.c @@ -146,9 +146,10 @@ struct nvme_nvm_command { }; }; +#define NVME_NVM_LP_MLC_PAIRS 886 struct nvme_nvm_lp_mlc { __u16 num_pairs; - __u8 pairs[886]; + __u8 pairs[NVME_NVM_LP_MLC_PAIRS]; }; struct nvme_nvm_lp_tbl { @@ -282,9 +283,14 @@ static int init_grps(struct nvm_id *nvm_id, struct nvme_nvm_id *nvme_nvm_id) memcpy(dst->lptbl.id, src->lptbl.id, 8); dst->lptbl.mlc.num_pairs = le16_to_cpu(src->lptbl.mlc.num_pairs); - /* 4 bits per pair */ + + if (dst->lptbl.mlc.num_pairs > NVME_NVM_LP_MLC_PAIRS) { + pr_err("nvm: number of MLC pairs not supported\n"); + return -EINVAL; + } + memcpy(dst->lptbl.mlc.pairs, src->lptbl.mlc.pairs, - dst->lptbl.mlc.num_pairs >> 1); + dst->lptbl.mlc.num_pairs); } }