Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3491704imu; Sun, 11 Nov 2018 16:18:38 -0800 (PST) X-Google-Smtp-Source: AJdET5dtRMVJOHsKl499yU62upJpCNMExYTtDEkWHJz+TVEdYwXr1zf/suCH8UO78ViWaMRy1m8i X-Received: by 2002:a62:571b:: with SMTP id l27-v6mr18188789pfb.209.1541981918666; Sun, 11 Nov 2018 16:18:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981918; cv=none; d=google.com; s=arc-20160816; b=vV/eDUNu/DOsNWj0SnNfDsu1vXUZUxgb4y9jbzrOYkEb3TOCi3/O3RaZJlXKI5gdIi k1C/j4brbEOIxIlat7AB7NFOjBkW52ZZl4fhwzte9WtgUNUon7o9cjquxzVLLRfgKm+G +CJHp8YnDU3y6mnU+oGHTBrMELD4lofYalXRvFAOshDUhQFwtFUuM3smDgjoeJZaykuB sIGQR8/rVjHKlaAebpO91CHx6IJxRDp6fM7dXpcDVxTnJIYJebkfQoUXs7YtfMqpTV3r tA2CgxI6I5rHnX7AGglO0c9y440tU4reGuic5/3Tzd+9bEoGYZ37lkxd3oF+DjWb5Baa 0xxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PZmHmmPes5S8Glghcb5uGFZIghxBYZFEYFHrKE6Fqng=; b=MAogETehB99BYnZbV8fCnwvOYDbhUo1WxrBfpfuQt+WkiYhaCzGTSzLRQiuXBohETC UiA77GZXUOG3bI4W/sG8OjmwvK0/w+A8Pns54OuKJfxZmN6ziafPeYhR40bzmWgbvLY5 y+7TXO86gdAEE5KabMZ9S7cfcJ72sYeoclPS967wJRxfooRkgUqWQtvwkpD/8+g+8uTc I3gcjY8VFxbyyk6NlCpPNKE9i71J/KUCBZvIuRhfgZrXqXOgLWmVnNKmfzV/8nxK2JaF I5L2YiPAODbKxbrXJavP44mfMdPXTBEXubLKcxREDM3hBnsxaech2xcYvQaAcmQO6Gut LXcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dis9WULR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si5096915pgj.177.2018.11.11.16.18.23; Sun, 11 Nov 2018 16:18:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dis9WULR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730033AbeKLIRA (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:59016 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729979AbeKLIQ7 (ORCPT ); Mon, 12 Nov 2018 03:16:59 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 722522241B; Sun, 11 Nov 2018 22:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975223; bh=Y9gSM/GIdjWjKb1O2fvgchbi3U8eW7o536VtklrlOtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dis9WULR0sKrjbj7LlyhuBwyJZxyJ+/aalIVFYU59yfnrl6FPbJMxvQ5PnSrtswKL OMVovShU8tU611VjKc3CXe+b/D5oxEYEvwM2JFQlpg/Hf2Sh24mir0D0Rc1dq8xdhD t0Lz3y1Tk1t3+7Oc9MxMe8U+AySk9ZF1q6lAVgcc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chuanhua Han , Boris Brezillon , Mark Brown Subject: [PATCH 4.19 009/361] spi: spi-mem: Adjust op len based on message/transfer size limitations Date: Sun, 11 Nov 2018 14:15:56 -0800 Message-Id: <20181111221621.232433284@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chuanhua Han commit e757996cafbeb6b71234a17130674bcd8f44c59e upstream. We need that to adjust the len of the 2nd transfer (called data in spi-mem) if it's too long to fit in a SPI message or SPI transfer. Fixes: c36ff266dc82 ("spi: Extend the core to ease integration of SPI memory controllers") Cc: Signed-off-by: Chuanhua Han Reviewed-by: Boris Brezillon Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-mem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -346,10 +346,25 @@ EXPORT_SYMBOL_GPL(spi_mem_get_name); int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) { struct spi_controller *ctlr = mem->spi->controller; + size_t len; + + len = sizeof(op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes; if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size) return ctlr->mem_ops->adjust_op_size(mem, op); + if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) { + if (len > spi_max_transfer_size(mem->spi)) + return -EINVAL; + + op->data.nbytes = min3((size_t)op->data.nbytes, + spi_max_transfer_size(mem->spi), + spi_max_message_size(mem->spi) - + len); + if (!op->data.nbytes) + return -EINVAL; + } + return 0; } EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);