Received: by 10.213.65.68 with SMTP id h4csp235467imn; Fri, 23 Mar 2018 03:34:01 -0700 (PDT) X-Google-Smtp-Source: AG47ELuAPr6EG24DYzP8ygJqZYk7+vafb5QSdLCT2Ooost9AH/k7mVlVhHCsd7qn76WUHfcSs1LP X-Received: by 10.99.160.25 with SMTP id r25mr17039734pge.95.1521801241458; Fri, 23 Mar 2018 03:34:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521801241; cv=none; d=google.com; s=arc-20160816; b=j7MTEvuFHnK1KTavgP1bFc+/3BH2WUPzPqoaRN96w5Lu0WTR85wJy6dXO+2MITDcAW OlIqMDAicueWZxvm+FR6ZhL/rI0UsdtpXte8ijbNKK1lQBH0s/hrBZRdx3FgFAyoNI5e lEM7sg1t6WCT9lLJzOOWZrbs415cjcQ/cdFj0x9/j2GOX2p8vo9ygzKkqYeacSkkftyE dcJ+9TqKYMlC9uQVkuv3YPAjZREraixyp9KOt6dnCBlUAsi//6lQVMnah6sDUe/JnvSr a1VrVJTJslAicRcw2jIUwsUund9MYHVUizTPkD+mgWIDlIcCUn5yZDhZqD/OAs/x2QjB 6uOA== 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=7hz7rEX9eIXdz26EmTZbENug2cKIem6Hcb1fwL+wXS8=; b=Pq77GJhMKBA21qDSynGLCZaesb0SqQhRIDqp1tVTmCFxdLuN2M1nrinb/jMIgzSToN ezDKVkcBFGp1p83+YfLyvvbHJxASz2+GZJj1x++uw1orh32KkrGbF9wXTuI1UbEQx0Sf IHliauRcNsJXEqUrp0688jbAf50brGiIp/mwOnPkJRSeOssub5w/mKgtbIP3k0rAebD8 Zc6XU6Jz7ALQoGvUh7H/9LAQrEAjNa42zVrB0KzNiii46lhUYglv80hYZC4DXv7hMBDM zyd53tDUXHVIbr5ES/OpQaJpkgVNgPBqQbcEaKdV3CLtM28fky9w+dmQ1z5HubR8aPnk 6wug== 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 l62si1446505pga.144.2018.03.23.03.33.46; Fri, 23 Mar 2018 03:34: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 S1756282AbeCWKcp (ORCPT + 99 others); Fri, 23 Mar 2018 06:32:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47696 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756118AbeCWKSa (ORCPT ); Fri, 23 Mar 2018 06:18:30 -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 8ED23F03; Fri, 23 Mar 2018 10:18:29 +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 3.18 09/47] [media] media/dvb-core: Race condition when writing to CAM Date: Fri, 23 Mar 2018 10:55:00 +0100 Message-Id: <20180323094248.522646244@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094248.117679641@linuxfoundation.org> References: <20180323094248.117679641@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 3.18-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 @@ -749,6 +749,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;