Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3885729imm; Mon, 20 Aug 2018 06:26:05 -0700 (PDT) X-Google-Smtp-Source: AA+uWPztrhOzzt6PaYv1cmpwsa/7aOxrxzvXoYDoNFNO017CnQ5wjO69kYdscINvqaRqkRP3qVut X-Received: by 2002:a17:902:8215:: with SMTP id x21-v6mr44968215pln.175.1534771565371; Mon, 20 Aug 2018 06:26:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534771565; cv=none; d=google.com; s=arc-20160816; b=UDgnpH5KexeMq/uMXHY8hIt4yLBaq30/bVaCphrN4XfR2qbXtvu0m3DWS1ShMY4xXg bE66uuEC5wd553LeTo1hK/PLoSSs1Grcf8NZLnyXxdEpZWXMqMkc+yJeULK6Uo+WLSAO uA6tVDs2uANikpgZQ11Mcj0dZtYAP5D9sy0vht1z7rDSNpDXpwzR5pX4yWIqV2G2VfBr AVdBv6RRq5fItP4getJ3jZkdQdoUxNZ0w20WjEuPUHf3tQYv/DjLqIxTvqP1Esy6RfVI n6LuY543RqniR81EZN+VskX63ODIKS3KSL4jQI897Y84d28ctMQZdSCKOYkAjmBj4qYz z1tg== 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 :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=ZiuNTZ2dvq0P93qAhWSquhfhxmvzjh5gFHfteFi23yM=; b=Gk1hSrudxk9+gJACp2b2iNvkqIxyU10MgpZjVYV6/eMASLZaR05ooS8cToriMzkrBv MC7czMfO3DbVVUguoOowCesUgU3v6VC2yWLFcngF+W2LJ7LUismrVbACg7I6wxFSTqZn ca7qCpnP6ZEQrmoup5VmwrXx75qP31UQrM3hNODW0tfGQrn/cY+cgpVGF81QC3Tu7e8c A1WV8lQJ7FAXfhZt6lb1stzHc1hN/MvlIMjTaAV7/yljuKlaspztHhZT2jrz6LIrbFr3 H2YjX+HQmA1Wj265MHN73Lg9F7Ibqux1/efgcds1KUUGLj1xvR8lb7szTHeRyeQoLaKk 7Ajg== ARC-Authentication-Results: i=1; mx.google.com; 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 m7-v6si10247680pfm.288.2018.08.20.06.25.47; Mon, 20 Aug 2018 06:26:05 -0700 (PDT) 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; 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 S1726729AbeHTQPL convert rfc822-to-8bit (ORCPT + 99 others); Mon, 20 Aug 2018 12:15:11 -0400 Received: from eu-smtp-delivery-211.mimecast.com ([146.101.78.211]:38598 "EHLO eu-smtp-delivery-211.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbeHTQPK (ORCPT ); Mon, 20 Aug 2018 12:15:10 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-63-psq3Hum6Nf-CiGHl1SCeGw-1; Mon, 20 Aug 2018 13:59:34 +0100 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b::d117) by AcuMS.aculab.com (fd9f:af1c:a25b::d117) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 20 Aug 2018 14:01:13 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Mon, 20 Aug 2018 14:01:13 +0100 From: David Laight To: 'Chuanhua Han' , "broonie@kernel.org" , "boris.brezillon@bootlin.com" CC: "linux-spi@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , "jiafei.pan@nxp.com" , "zhiqiang.hou@nxp.com" Subject: RE: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API Thread-Topic: [PATCH] mtd: m25p80: consider max message size when use the spi_mem_xx() API Thread-Index: AQHUOIO1v0mwy7J+K0+V94NCbAoDI6TImGqw Date: Mon, 20 Aug 2018 13:01:13 +0000 Message-ID: <109aeb2622924f20b29743746bb77ce2@AcuMS.aculab.com> References: <1534769013-43449-1-git-send-email-chuanhua.han@nxp.com> In-Reply-To: <1534769013-43449-1-git-send-email-chuanhua.han@nxp.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.33] MIME-Version: 1.0 X-MC-Unique: psq3Hum6Nf-CiGHl1SCeGw-1 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 From: Chuanhua Han > Sent: 20 August 2018 13:44 > > Signed-off-by: Chuanhua Han > --- > Changes in v3: > Rename variable name "val" to "opcode_addr_dummy_sum". > Place the legitimacy of the transfer size(i.e., "pi_max_message_size(mem->spi)" and > "opcode_addr_dummy_sum") into "if (! ctlr - > mem_ops | |! ctlr-> mem_ops->exec_op) {" > structure and add "spi_max_transfer_size(mem->spi) and opcode_addr_dummy_sum". > Adjust the formatting alignment of your code. > "(unsigned long)op->data.nbytes" was modified to "(unsigned long)(op->data.nbytes)". > > Fixes: c36ff266dc82 ("spi: Extend the core to ease integration of SPI memory controllers") > --- > drivers/spi/spi-mem.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index 990770d..5ec2bc9 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -328,10 +328,24 @@ EXPORT_SYMBOL_GPL(spi_mem_exec_op); > int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) > { > struct spi_controller *ctlr = mem->spi->controller; > + unsigned long opcode_addr_dummy_sum = sizeof(op->cmd.opcode) + > + op->addr.nbytes + > + op->dummy.nbytes; I'd split that (and shorten the variable name) to avoid line wrap. Maybe: unsigned long 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 (spi_max_message_size(mem->spi) < opcode_addr_dummy_sum || > + spi_max_transfer_size(mem->spi) < opcode_addr_dummy_sum) > + return -EINVAL; Those comparisons are lexically backwards, you want 'value op constant'. So: if (len > spi_max_message_size(mem->spi) || len > spi_max_transfer_size(mem->spi)) return -EINVAL. Although I'm surprised you need to do both comparisons. > + > + op->data.nbytes = min3((unsigned long)(op->data.nbytes), > + spi_max_transfer_size(mem->spi), > + spi_max_message_size(mem->spi) - > + opcode_addr_dummy_sum); That looks like a strange limit... > + } > + > return 0; > } > EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size); > -- > 2.7.4 David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)