From patchwork Wed Mar 19 03:53:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Lin X-Patchwork-Id: 3857121 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 541E6BF540 for ; Wed, 19 Mar 2014 18:03:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7FBCE20120 for ; Wed, 19 Mar 2014 18:03:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B29822021F for ; Wed, 19 Mar 2014 18:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757412AbaCSDxy (ORCPT ); Tue, 18 Mar 2014 23:53:54 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:47332 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756662AbaCSDxx (ORCPT ); Tue, 18 Mar 2014 23:53:53 -0400 Received: by mail-pa0-f48.google.com with SMTP id hz1so8330929pad.35 for ; Tue, 18 Mar 2014 20:53:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:content-type :mime-version:content-transfer-encoding; bh=htFfbJpO+cjr2viYBBgpKZ63Big9y91bbD2OlzdOF8Y=; b=lG3C7eODEKZiFR2eGwqvi1vclMOF6pI8LuDUlC/hIatPfwQ/zfT5ESU1reIaXbdI3T tFtCADE62WVc7GNj9AckFJ3QhQGMtPd/iWsSWnFNEXArsRrFQZdTFfVpM6uYlj2TG/pH Q27jN67XtbPYzQ4R8DYZwmr5UPzuas99r1BFgQgfGhSAxEwqd8mfW3Aan7abG6IIfnSs zzFcyrO7Gvl2MK4XVsLxbFfJA/qr670rtusgAy99/qgEzUfUhu97gcqSK6xkOtWXM3G1 eBEgikkg07iq3212YQgXq/FP4oatJ4QD8jHYYba1rGz0aQgCpOZnVa/1ieANuCT9OpK9 9lwQ== X-Gm-Message-State: ALoCoQnvNjF2pxaSHuP2+JSuOrACyJIg5MGmsNZGfOw5tRddBr17aQ1O9R/lVub7n3SJ+ocUwo7v X-Received: by 10.68.233.37 with SMTP id tt5mr15244586pbc.154.1395201233013; Tue, 18 Mar 2014 20:53:53 -0700 (PDT) Received: from [192.168.0.102] (218-164-140-191.dynamic.hinet.net. [218.164.140.191]) by mx.google.com with ESMTPSA id ac5sm57597087pbc.37.2014.03.18.20.53.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Mar 2014 20:53:52 -0700 (PDT) Message-ID: <1395201227.16346.1.camel@phoenix> Subject: [PATCH 1/7] spi: core: Validate Tx/Rx buffers for non-zero length transfer From: Axel Lin To: Mark Brown Cc: Wenyou Yang , Fabrice Crohas , Illia Smyrnov , Atsushi Nemoto , Lars-Peter Clausen , linux-spi@vger.kernel.org Date: Wed, 19 Mar 2014 11:53:47 +0800 X-Mailer: Evolution 3.8.4-0ubuntu1 Mime-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 Reject transfer if both tx_buf and rx_buf are NULL for non-zero length transfer. Add the checking in spi core so we can remove the same checking in various drivers. Signed-off-by: Axel Lin --- drivers/spi/spi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 26b331d..0a29d2a 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1876,6 +1876,10 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) if (xfer->len % w_size) return -EINVAL; + /* non-zero length transfer must has tx_buf or rx_buf */ + if (xfer->len && !xfer->tx_buf && !xfer->rx_buf) + return -EINVAL; + if (xfer->speed_hz && master->min_speed_hz && xfer->speed_hz < master->min_speed_hz) return -EINVAL;