Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp11623pxb; Fri, 15 Jan 2021 04:38:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzaN3wYNnCbgnVYDcWZiQyc/dZjoN9U7GvRCaZFLWLxixaXMtTc0PpOyUya38ahEhJAarsx X-Received: by 2002:a17:906:1958:: with SMTP id b24mr4638680eje.263.1610714284252; Fri, 15 Jan 2021 04:38:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610714284; cv=none; d=google.com; s=arc-20160816; b=ptS61aaPJOipwxCE0X0A6n30AQI+eheQThRSwPkV+y/DX9ZVXuXIQLvI5tFjwH/CNL aBJpzf3bXLZ67U7LH6hGkttnUV7jCWbyWmYP9RXUfdsMSvuxLU3FBTl8vf/GpBVFVUf3 dAnQurX6gwOcJ+cs4aoAw0Hg33j7jp+/Cdix0D46RVd1qKrq8w/UOeJ6kHiUaQnIzz4H DClqD61HvGztCcrtz3BpLn1NieDJvrbwxVN15EAjQYbzTucJSTHI1biAuDBf9QenGEz+ cBqoTQIXUSAwPdvnOLWm1KeUY2SRdWOfnOpaSqC8M+29nAOfEXXCg95YLL3/chz/0M1h 395w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Mpp+qqzLSPgBy6iF8xA6QB/z8V8J2umsFAGsoDHarmg=; b=ColpLFFpqctJzYi2KOa3ZQCn1NIA2icEO0qDy5kqY0WlQ092BEsnHTZAU6hsTuLZdv 9VGXRd5XtSk2YNi/3m5PCgeID+JVIPfh6pkaIqO8etr7QNx0iOQiCcG3lccOtAwHITVv nTzGusGj0294pEXPnTPhvWk4dgPBU4kHV1Q427O/PSSQJG60qeOrzz0c/d7pn0KPaTWM 7uQPQjDgHsoZPLH3E3D/2di2F5ar6vWQt8aN4tM9ghYiopdUcse/zK+119SQzqSAWlgn uFmUbWoFkXs8ad+J5WjxXiF8c7D/o1AVjDHLbZxXKT9ktxIxZQwS4ytLUE5BlyI/AP5I ws6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E2BjGDEF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j15si4255184edv.474.2021.01.15.04.37.40; Fri, 15 Jan 2021 04:38:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E2BjGDEF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387679AbhAOMf3 (ORCPT + 99 others); Fri, 15 Jan 2021 07:35:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:42246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387630AbhAOMfO (ORCPT ); Fri, 15 Jan 2021 07:35:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DCF442333E; Fri, 15 Jan 2021 12:34:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714074; bh=os7dohcj4+JctHTLwnzDesgBjZRrYjO2vXdt/AByoF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E2BjGDEF896uNVTPC5++D8gMt4Q7VDZdOOyx98/3gt0cDHVilxfPb5F6kUb9bVpuZ n3w+wep9ve4+/Xg06cqbsMB+mQ9TLA6o3mZFQN7igzbvO20x9c8KNMczOj5ITc5QXa XF4EFrbRJtr9xBu3hbin5ilW4DAkHYIOjcbtYFrs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linhua Xu , Chunyan Zhang , Wolfram Sang Subject: [PATCH 5.4 34/62] i2c: sprd: use a specific timeout to avoid system hang up issue Date: Fri, 15 Jan 2021 13:27:56 +0100 Message-Id: <20210115122000.049519779@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chunyan Zhang commit 0b884fe71f9ee6a5df35e677154256ea2099ebb8 upstream. If the i2c device SCL bus being pulled up due to some exception before message transfer done, the system cannot receive the completing interrupt signal any more, it would not exit waiting loop until MAX_SCHEDULE_TIMEOUT jiffies eclipse, that would make the system seemed hang up. To avoid that happen, this patch adds a specific timeout for message transfer. Fixes: 8b9ec0719834 ("i2c: Add Spreadtrum I2C controller driver") Signed-off-by: Linhua Xu Signed-off-by: Chunyan Zhang [wsa: changed errno to ETIMEDOUT] Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-sprd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -72,6 +72,8 @@ /* timeout (ms) for pm runtime autosuspend */ #define SPRD_I2C_PM_TIMEOUT 1000 +/* timeout (ms) for transfer message */ +#define I2C_XFER_TIMEOUT 1000 /* SPRD i2c data structure */ struct sprd_i2c { @@ -244,6 +246,7 @@ static int sprd_i2c_handle_msg(struct i2 struct i2c_msg *msg, bool is_last_msg) { struct sprd_i2c *i2c_dev = i2c_adap->algo_data; + unsigned long time_left; i2c_dev->msg = msg; i2c_dev->buf = msg->buf; @@ -273,7 +276,10 @@ static int sprd_i2c_handle_msg(struct i2 sprd_i2c_opt_start(i2c_dev); - wait_for_completion(&i2c_dev->complete); + time_left = wait_for_completion_timeout(&i2c_dev->complete, + msecs_to_jiffies(I2C_XFER_TIMEOUT)); + if (!time_left) + return -ETIMEDOUT; return i2c_dev->err; }