Received: by 10.213.65.68 with SMTP id h4csp215982imn; Fri, 23 Mar 2018 03:06:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELsXaQnkZlt6i06gvIR6Iam8tkOg+oDshdXyxir7b872i/FV4pVBi2BAkQYNRrApo2jtB+jl X-Received: by 10.98.9.72 with SMTP id e69mr7860013pfd.197.1521799561885; Fri, 23 Mar 2018 03:06:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521799561; cv=none; d=google.com; s=arc-20160816; b=LVg7Sk5MNBvIxXE8mxeQcw3T7Xpy6b/ATFAtzZJRiw778Kypb1/Ygq+eSd/56DCTSW gctgpsYWox0aoHuXHOwJ2LbOpS/moSgkoVKLIWFBmxL6wr3xs95D4MhOcPOAK5N8Jr8c dHkye9KqmkxXkA1W61ApzAjZFyQkzndl1M0tu8fRFxmZ1NEAYvyMYszNwhc2O7OpsUTi f3msmTf5/joD9P6YU69V192GSaPSR0ycT1MjJM+b/nCaGHzrJjphTuIKDkaHGFdQbZ7W FXFsEodzCf+sDyiScfDpEKrY4aL91s+XuYRIPuJSV+Ri3IHLlUp/tebbRawQxEnw8uRr MXiw== 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=zMK9ut2i1ow6VULibp0jTWMc5ZMS2SyMgYYQzGPmipY=; b=DqX2ES0nK7Dqkqge9Rkbgcv5E2QoobO048ouwuwuDMqrooOnfBu1QmPRWG3A9Jn32T I9K1IwiqM7MEvL0HgKgfARLIFhAYIeKdfLAuaxDrcaFyqc1ubSItSsGJ9Pom41ZO5QAF 7ExmCNCIrhkV5xtK4LfcdwutIn4TzHMxtOoPWf/WmYMn22D/WTdM5gaT4Bpj3eaw4+/P 6q6WLAFhg8+ddZM71kZ1T709i8Wk4PKa86xm7Z4hXpKt8LREHR00qLQJoRVVK3CN8UtS UBRUKFlH4inK+Dm/OuoVNAqRZtYTH8HkPlTSWgRlFI3WCxpVksSZgDf4K6J3HwxBpshA fy+A== 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 o6-v6si2156845plk.746.2018.03.23.03.05.47; Fri, 23 Mar 2018 03:06:01 -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 S1754813AbeCWKEr (ORCPT + 99 others); Fri, 23 Mar 2018 06:04:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:39284 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754747AbeCWKEp (ORCPT ); Fri, 23 Mar 2018 06:04:45 -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 3A42913DB; Fri, 23 Mar 2018 10:04:45 +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.9 022/177] [media] media/dvb-core: Race condition when writing to CAM Date: Fri, 23 Mar 2018 10:52:30 +0100 Message-Id: <20180323094206.173538297@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094205.090519271@linuxfoundation.org> References: <20180323094205.090519271@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.9-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 @@ -779,6 +779,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;