Received: by 10.213.65.68 with SMTP id h4csp247860imn; Fri, 23 Mar 2018 03:53:04 -0700 (PDT) X-Google-Smtp-Source: AG47ELtWf2cMPaCWTm+cbhRCyqj2/30TVqErzELfLLsLEC3stCZxzQGbNBJ8GqaBsRzt/zPn3vzp X-Received: by 10.98.185.11 with SMTP id z11mr23489657pfe.153.1521802384248; Fri, 23 Mar 2018 03:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521802384; cv=none; d=google.com; s=arc-20160816; b=qdRxoqMwhzT/Xzk2VLreZOdGghuBEY7RXXGckVb2XaVd3fT9fF0Zlw5AmznJGUTKwR sAfiqL/yCWXhzZQnXuHCa26z33Mma7oxzfiyu3U29FlP0NUr9sYGHY6stslGBODpHKQ9 K+nHJXChMN/2gA7qGQUJtdhX3fPX6TrCu4WM3+vdJEjPj1wKR1RE2xD/GZh4DQLTBHk1 ABOpqB6b2XBIrN8Vvg3xAX6+ckhj5oHoS1/Jpn7BMD0xA2b9XtpN/1+O/nA92zIBTEdh xz+oppiUE3Mn/dz3EFlHsbRXyi8Qe/sFs4wxzOTqYZGmA/LLRqtOPm2cJDlGRAgtGbVe oolQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HuZn/SpWU6nzDoshYtLnvXbYkuL9eNslugSogniAqT0=; b=DZE40GF5CQTt0ryVGb/nU8ZcHIjIgQCi/2qgBy+94CHKT7OWymcDsyw70JqIdam16k hRFHJLRD6Kt6FnQaXREhyJam9tPeQdVIkcI+dpib/uk02nhx7hBViRmjibupik9cSRvS 7/QI4AbwtQHVg3mA+qooccNjY5KPmZtqQ52KVuqBvpbgA1BrOi4r/OJ3nZBqDY3nFYeN lX2kFfhSJxeU5SjVYXpFMukTQa81+jeRBjHHedfnOyoYmzDankUXZOgAZ7RQ92fDZAL/ luJzd7sLZoFL182s7jbWBJEHR9/Li35tCWpjNvUc+ZMxPPb7t29N83Or9Tm/DQVKEp/l BAwA== 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 p12-v6si7900276plk.295.2018.03.23.03.52.50; Fri, 23 Mar 2018 03:53:04 -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 S1752434AbeCWKwC (ORCPT + 99 others); Fri, 23 Mar 2018 06:52:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45076 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755986AbeCWKOL (ORCPT ); Fri, 23 Mar 2018 06:14:11 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5234F1224; Fri, 23 Mar 2018 10:14:10 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jasmin jessich , Ralph Metzler , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.4 18/97] [media] media/dvb-core: Race condition when writing to CAM Date: Fri, 23 Mar 2018 10:54:05 +0100 Message-Id: <20180323094158.512948472@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jasmin J [ Upstream commit e7080d4471d805d921a9ea21b32f911a91e248cb ] It started with a sporadic message in syslog: "CAM tried to send a buffer larger than the ecount size" This message is not the fault itself, but a consecutive fault, after a read error from the CAM. This happens only on several CAMs, several hardware, and of course sporadic. It is a consecutive fault, if the last read from the CAM did fail. I guess this will not happen on all CAMs, but at least it did on mine. There was a write error to the CAM and during the re-initialization procedure, the CAM finished the last read, although it got a RS. The write error to the CAM happened because a race condition between HC write, checking DA and FR. This patch added an additional check for DA(RE), just after checking FR. It is important to read the CAMs status register again, to give the CAM the necessary time for a proper reaction to HC. Please note the description within the source code (patch below). [mchehab@s-opensource.com: make checkpatch happy] Signed-off-by: Jasmin jessich Tested-by: Ralph Metzler Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/media/dvb-core/dvb_ca_en50221.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) --- a/drivers/media/dvb-core/dvb_ca_en50221.c +++ b/drivers/media/dvb-core/dvb_ca_en50221.c @@ -750,6 +750,29 @@ static int dvb_ca_en50221_write_data(str goto exit; } + /* + * It may need some time for the CAM to settle down, or there might + * be a race condition between the CAM, writing HC and our last + * check for DA. This happens, if the CAM asserts DA, just after + * checking DA before we are setting HC. In this case it might be + * a bug in the CAM to keep the FR bit, the lower layer/HW + * communication requires a longer timeout or the CAM needs more + * time internally. But this happens in reality! + * We need to read the status from the HW again and do the same + * we did for the previous check for DA + */ + status = ca->pub->read_cam_control(ca->pub, slot, CTRLIF_STATUS); + if (status < 0) + goto exit; + + if (status & (STATUSREG_DA | STATUSREG_RE)) { + if (status & STATUSREG_DA) + dvb_ca_en50221_thread_wakeup(ca); + + status = -EAGAIN; + goto exit; + } + /* send the amount of data */ if ((status = ca->pub->write_cam_control(ca->pub, slot, CTRLIF_SIZE_HIGH, bytes_write >> 8)) != 0) goto exit;