From patchwork Thu Feb 4 14:13:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 8222291 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 A3F619F1C0 for ; Thu, 4 Feb 2016 14:14:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BBE0120397 for ; Thu, 4 Feb 2016 14:13:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7AC3A20395 for ; Thu, 4 Feb 2016 14:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965627AbcBDONn (ORCPT ); Thu, 4 Feb 2016 09:13:43 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:33587 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965435AbcBDONl (ORCPT ); Thu, 4 Feb 2016 09:13:41 -0500 Received: by mail-wm0-f41.google.com with SMTP id g62so6348344wme.0 for ; Thu, 04 Feb 2016 06:13:40 -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 :mime-version:content-type:content-transfer-encoding; bh=hemdl6kuFecIvctOjFlvc5eiy2fkflfpBVxiVjN6pig=; b=AC57iAUTA0RCP9pse1iFPlCz809D+oC9/0X/Yp9Xyw4PlT3jGBajogXanY14wdOlZ/ EOqpha5HcDZsZoJUtdj+wMKQi4pgHBfyQ8niQuhyLqt+jLztkseJ+Y/UeAB3Mtctjugz 7ygLz33tDShyIf7LeZp1BBzAoIGfm56q3kdsI= 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:mime-version:content-type:content-transfer-encoding; bh=hemdl6kuFecIvctOjFlvc5eiy2fkflfpBVxiVjN6pig=; b=c1DinzsUfT6Arpfvpr7db5+EDQwEo5p1Br2ZIe+eA91CxeNBKy+PRBnPzM5mU626Ma aFb12ranGHT4PSlu9CSocWJng9jggBXCcGyuxVnGsQ7YCyt87CKprvbJ3ix9Pk6AgC1d Wd6pPDzmbYyb7Vs4a9mbxvbCllZqGqjMI9hcC1Kq7udW45gY65ULz2wLDAFpDvuYut4Y HAu33/svUn7hxASCVnK6UgwOgTHWyJxgMq0ybJviZCAxpM6dFGKNoZN+9wbRYm37J8qY 2sPM3QAh//84+AZCzX0lAINUaLL97kRY9UsNOwlQPuIuNBi/TTR8M60ULCtk1vyh8h0P +znA== X-Gm-Message-State: AG10YORluwNnDZwCU7PA22I1az/QYvuewK3eAEjkK1/U/zsPYbB3et/lH1goYKqsjxsfjQ== X-Received: by 10.28.186.10 with SMTP id k10mr2129249wmf.99.1454595220242; Thu, 04 Feb 2016 06:13:40 -0800 (PST) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id u130sm26390332wmg.15.2016.02.04.06.13.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Feb 2016 06:13:39 -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 15:13:26 +0100 Message-Id: <1454595207-22432-5-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1454595207-22432-1-git-send-email-m@bjorling.me> References: <1454595207-22432-1-git-send-email-m@bjorling.me> MIME-Version: 1.0 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" Signed-off-by: Matias Bjørling --- 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); } }