Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp6207582imm; Mon, 23 Jul 2018 13:30:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe+KewkUT+KO6P3vORMhQQl5oN+MWaqBegGCbYKyspe5GwmSXzGTD2FAyRAT7881+mpYm9k X-Received: by 2002:a65:6699:: with SMTP id b25-v6mr13701367pgw.426.1532377819355; Mon, 23 Jul 2018 13:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532377819; cv=none; d=google.com; s=arc-20160816; b=VMVqgdXPfpn9WVsUMzhn3jZhs00v523XCQpGlwaJa12e1jBpFlzvjpBJNUbRakHPR+ sFoC1SyEfob4R6Db/kJcQiJFUmaaxTUMw+IFyTfz0ulN89HaiKdxo95YpTnC+7/4BiBd 1M3oz0x+q4rXMdDc/tHsGlckEaoktGy3DddsaYJdFu7eWTw90GOMag10onDwCrB0BRzf QMEbS1UZ0c+hAaJFRiHFic20IA1/NU+pwUHSWl0vRtTvPd+B5ZNRSm2Wgtzf6JdsbIfu Tnd/SeFqffXFkKJUYRhGAu+ynb/iXO6eql8iNaqtYQuNMMQ6eItkaQ6rcSNlaW/JybaS 2EGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=guGO0pVcEJGdaPold0/4Liq6O1/tDK3S9NRLLDn/KcY=; b=x9GM0BZFBKlN//bB9SvAOJyazO1SwBvYGwke4pJI+68XSClSAJySSszSIvj8gYgtV4 ol2iZutVzwaQOfSXsjYO75Ld90K5pv/+Vqa717QEF0QxGCLh2KEAnrx79VtwoufO5/J3 68o5HQf3gpd+mIWw88fZim4jcBAkT8E4JPN8y6XC/o63PtocuPqP1NOkIynboKaau3Ks izNGmlA6tYPGaQCoZoIzg9POsXEAaeK8Jnt6vWd5fK8EZM7iYcoc2OjWGmUSUhShuZav yiG88s+uOSevLoiyfds8nxS7H8GiMZ4ND2U3QaC0q+3sJQT2Iqztq76B1VFVceGJaSXi Sn4A== 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 r6-v6si9715138pgm.647.2018.07.23.13.30.04; Mon, 23 Jul 2018 13:30:19 -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 S2388137AbeGWV3r (ORCPT + 99 others); Mon, 23 Jul 2018 17:29:47 -0400 Received: from sauhun.de ([88.99.104.3]:51232 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388062AbeGWV3r (ORCPT ); Mon, 23 Jul 2018 17:29:47 -0400 Received: from localhost (p54B3377D.dip0.t-ipconnect.de [84.179.55.125]) by pokefinder.org (Postfix) with ESMTPSA id C60A7631A4A; Mon, 23 Jul 2018 22:26:52 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Wolfram Sang , Wolfram Sang , linux-kernel@vger.kernel.org Subject: [PATCH 01/12] i2c: quirks: add zero length checks Date: Mon, 23 Jul 2018 22:26:05 +0200 Message-Id: <20180723202617.15230-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180723202617.15230-1-wsa+renesas@sang-engineering.com> References: <20180723202617.15230-1-wsa+renesas@sang-engineering.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some adapters do not support a message length of 0. Add this as a quirk so drivers don't have to open code it. Signed-off-by: Wolfram Sang --- Only build tested. drivers/i2c/i2c-core-base.c | 6 ++++++ include/linux/i2c.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 02d6f27b19e4..a26b3e9cc441 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1839,9 +1839,15 @@ static int i2c_check_for_quirks(struct i2c_adapter *adap, struct i2c_msg *msgs, if (msgs[i].flags & I2C_M_RD) { if (do_len_check && i2c_quirk_exceeded(len, q->max_read_len)) return i2c_quirk_error(adap, &msgs[i], "msg too long"); + + if (q->flags & I2C_AQ_NO_ZERO_LEN_READ && len == 0) + return i2c_quirk_error(adap, &msgs[i], "no zero length"); } else { if (do_len_check && i2c_quirk_exceeded(len, q->max_write_len)) return i2c_quirk_error(adap, &msgs[i], "msg too long"); + + if (q->flags & I2C_AQ_NO_ZERO_LEN_WRITE && len == 0) + return i2c_quirk_error(adap, &msgs[i], "no zero length"); } } diff --git a/include/linux/i2c.h b/include/linux/i2c.h index bc8d42f8544f..2a98d0886d2e 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -661,6 +661,10 @@ struct i2c_adapter_quirks { I2C_AQ_COMB_READ_SECOND | I2C_AQ_COMB_SAME_ADDR) /* clock stretching is not supported */ #define I2C_AQ_NO_CLK_STRETCH BIT(4) +/* message cannot have length of 0 */ +#define I2C_AQ_NO_ZERO_LEN_READ BIT(5) +#define I2C_AQ_NO_ZERO_LEN_WRITE BIT(6) +#define I2C_AQ_NO_ZERO_LEN (I2C_AQ_NO_ZERO_LEN_READ | I2C_AQ_NO_ZERO_LEN_WRITE) /* * i2c_adapter is the structure used to identify a physical i2c bus along -- 2.11.0