From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753812AbeAKFM5 (ORCPT + 1 other); Thu, 11 Jan 2018 00:12:57 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:43762 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753765AbeAKFKJ (ORCPT ); Thu, 11 Jan 2018 00:10:09 -0500 From: Jianchao Wang To: keith.busch@intel.com, axboe@fb.com, hch@lst.de, sagi@grimberg.me Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] nvme-pci: calculate iod and avg_seg_size just before use them Date: Thu, 11 Jan 2018 13:09:39 +0800 Message-Id: <1515647379-1877-1-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8770 signatures=668652 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=997 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801110067 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: The calculation of iod and avg_seg_size maybe meaningless if nvme_pci_use_sgls returns before uses them. So calculate just before use them. Signed-off-by: Jianchao Wang --- drivers/nvme/host/pci.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 0530432..733b4f4 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -772,16 +772,19 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev, static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req) { - struct nvme_iod *iod = blk_mq_rq_to_pdu(req); + struct nvme_iod *iod; unsigned int avg_seg_size; - avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req), - blk_rq_nr_phys_segments(req)); - if (!(dev->ctrl.sgls & ((1 << 0) | (1 << 1)))) return false; + + iod = blk_mq_rq_to_pdu(req); if (!iod->nvmeq->qid) return false; + + avg_seg_size = DIV_ROUND_UP(blk_rq_payload_bytes(req), + blk_rq_nr_phys_segments(req)); + if (!sgl_threshold || avg_seg_size < sgl_threshold) return false; return true; -- 2.7.4