From patchwork Mon Aug 22 18:55:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 661598 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3sJ2pX11g8z9sDf for ; Tue, 23 Aug 2016 04:56:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=uGx8UMQv; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753670AbcHVSzv (ORCPT ); Mon, 22 Aug 2016 14:55:51 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34187 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753549AbcHVSzt (ORCPT ); Mon, 22 Aug 2016 14:55:49 -0400 Received: by mail-pf0-f196.google.com with SMTP id g202so6803901pfb.1; Mon, 22 Aug 2016 11:55:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=4TlkhjvYiqw3FcJaZ2UamRvbXqvYFS0NYonTfbrZAA0=; b=uGx8UMQv+XfrbqYwKqFRQ4BoUZ5SRRenOU01FaeqwnZBH51SGnIV30DfjXfKI2cvS2 BRCOhxfgFigr+GTIiPzEjYfJQesGZh41CV8SGSNvkjVSwhJexQIYoHi1n+ZmWNmU+I+2 tKu8pPC/kDGOVaxUzY3auBu7faGg8XJ82wSEumE4RmGFhRk4qax0b+yLe+DyZjHMdBi/ LGYmWf9+Lb79UKQPDmpTZmwKzFtw1UV1kJc0xQnZH4iEBgPYizxIQMA3VXM8PGKWFOR0 g0gSQx1+7sapZNcJlkXtWdr8wCd4k3YMMl08AIq+NTIcAIQdU9nUDFOeQLZm2fPLmxvI VDOQ== 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; bh=4TlkhjvYiqw3FcJaZ2UamRvbXqvYFS0NYonTfbrZAA0=; b=GwKfautWxkadyAWeRCSUKGLxg6WFhzx9sE0yypN6hmbp4Ry0rtBDKKdkXFogakVtPT OMOBOjLRxwCvPMW85pVzXYSMWp11DE2RV0q8gzzw4MxlzpFZcQW7iiyIuA+LU+cfu6Yt tnwbAkFhoQ/CYuTv8UJaeK4p43dgseBcB5t7gAdNd1HxRqDkB4Hr4NpCqmSeUzHVQn/6 WSAWNAewbK3hLyKpnZPR+A0moj3mXmpdBHIep2WpvjeCp0PF7VDE4FcPab9Dzs7JHNxX jYXNFfl7ZcRvwemYcpdl2yMpeEGVnFmGJzrO1B0Ei0Je1rDyOTcj6XcGOOmoHFPd3Wa8 a+rg== X-Gm-Message-State: AEkooutUY0QOivs1aQGiBp8Azpfdg/4g7bokbpqLluVXHjbh30FJtWEqWbRLxZjQmg+xVw== X-Received: by 10.98.87.90 with SMTP id l87mr45492042pfb.133.1471892148285; Mon, 22 Aug 2016 11:55:48 -0700 (PDT) Received: from localhost.localdomain (n219073059164.netvigator.com. [219.73.59.164]) by smtp.gmail.com with ESMTPSA id f84sm28917380pfd.87.2016.08.22.11.55.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Aug 2016 11:55:46 -0700 (PDT) From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, martin.petersen@oracle.com, shaun.tancheff@seagate.com, shaun@tancheff.com Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH] ata: do not hard code limit in ata_set_lba_range_entries() Date: Tue, 23 Aug 2016 02:55:40 +0800 Message-Id: X-Mailer: git-send-email 2.9.3 Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org From: Tom Yan In commit 5c79097a28c2 ("libata-scsi: reject WRITE SAME (16) with n_block that exceeds limit"), it is made sure that ata_set_lba_range_entries() will never be called with a request size (n_block) that is larger than the number of blocks that a 512-byte block TRIM payload can describe (65535 * 64 = 4194240), in addition to acknowlegding the SCSI/block layer with the same limit by advertising it as the Maximum Write Same Length. Therefore, it is unnecessary to hard code the same limit in ata_set_lba_range_entries() itself, which would only cost extra maintenance effort. Such effort can be noticed in, for example, commit 2983860c7668 ("libata-scsi: avoid repeated calculation of number of TRIM ranges"). Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index be9c76c..9b74ecb 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3322,7 +3322,7 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) buf = page_address(sg_page(scsi_sglist(scmd))); if (n_block <= 65535 * ATA_MAX_TRIM_RNUM) { - size = ata_set_lba_range_entries(buf, ATA_MAX_TRIM_RNUM, block, n_block); + size = ata_set_lba_range_entries(buf, block, n_block); } else { fp = 2; goto invalid_fld; diff --git a/include/linux/ata.h b/include/linux/ata.h index adbc812..5e2e9ad 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -1077,19 +1077,19 @@ static inline void ata_id_to_hd_driveid(u16 *id) * TO NV CACHE PINNED SET. */ static inline unsigned ata_set_lba_range_entries(void *_buffer, - unsigned num, u64 sector, unsigned long count) + u64 sector, unsigned long count) { __le64 *buffer = _buffer; unsigned i = 0, used_bytes; - while (i < num) { - u64 entry = sector | - ((u64)(count > 0xffff ? 0xffff : count) << 48); + while (count > 0) { + u64 range, entry; + + range = count > 0xffff ? 0xffff : count; + entry = sector | (range << 48); buffer[i++] = __cpu_to_le64(entry); - if (count <= 0xffff) - break; - count -= 0xffff; - sector += 0xffff; + count -= range; + sector += range; } used_bytes = ALIGN(i * 8, 512);