From patchwork Tue Sep 14 15:18:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Young X-Patchwork-Id: 511665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 774BBC4332F for ; Tue, 14 Sep 2021 15:18:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5918961168 for ; Tue, 14 Sep 2021 15:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234274AbhINPTc (ORCPT ); Tue, 14 Sep 2021 11:19:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234273AbhINPTb (ORCPT ); Tue, 14 Sep 2021 11:19:31 -0400 Received: from gofer.mess.org (gofer.mess.org [IPv6:2a02:8011:d000:212::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 685FBC0613CF; Tue, 14 Sep 2021 08:18:12 -0700 (PDT) Received: by gofer.mess.org (Postfix, from userid 1000) id 654D4C6355; Tue, 14 Sep 2021 16:18:09 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mess.org; s=2020; t=1631632689; bh=/IhPmIr9/LHDBv8I1A2poHCsQ9nOxmqZ/x5osrJSJAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDiLzAMPXiYDuvfH6vtr9I65enS3LtscCNuUkisqFNv2FXKReQgFn+Eh+yZCGONT9 E8yg2mv83s23k45nzOEXJwxWjALbUXl7iyh98c8S8lGEfRWakfHS3Dbfzd+0u5TZzH rBORpK2YG1MSh2kVGjtWhtKj6BXRndQK1kSd0FVzg3t6GuZ4r6XZLFz7NR+sEMIqMs Xt0bp01VbBFxlpvXpOCKXSLRP1HlkY09Pnhn6OmAEBXBRjKvjMShz7gQpIqinrSXBB LSJrwJyKywsncjGl0OtLNVf+tmdNwmTJBhnEPLUrFKmd+7YZd/GvZZsNzaRKldv2yD ktuXrGtBQpn6Q== From: Sean Young To: linux-media@vger.kernel.org Cc: Georgi Bakalski , stable@vger.kernel.org Subject: [PATCH 2/4] media: ir_toy: deal with residual irdata before expected response Date: Tue, 14 Sep 2021 16:18:07 +0100 Message-Id: <2b28f45034d54371fe420f3a54c7eb93034024e1.1631632442.git.sean@mess.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <22eeae667aac9d5eaaae2f21904f238ebef0c05b.1631632442.git.sean@mess.org> References: <22eeae667aac9d5eaaae2f21904f238ebef0c05b.1631632442.git.sean@mess.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org After sending the start transmit command, the device is supposed to respond with the length of the buffer which can be sent. There might be some residual ir data there. Cc: stable@vger.kernel.org Signed-off-by: Sean Young --- drivers/media/rc/ir_toy.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c index 45d39b6e49c0..2b7c8bba4d6a 100644 --- a/drivers/media/rc/ir_toy.c +++ b/drivers/media/rc/ir_toy.c @@ -122,6 +122,7 @@ static void irtoy_response(struct irtoy *irtoy, u32 len) len, irtoy->in); } break; + case STATE_COMMAND_NO_RESP: case STATE_IRDATA: { struct ir_raw_event rawir = { .pulse = irtoy->pulse }; __be16 *in = (__be16 *)irtoy->in; @@ -167,10 +168,8 @@ static void irtoy_response(struct irtoy *irtoy, u32 len) int err; if (len != 1 || space > MAX_PACKET || space == 0) { - dev_err(irtoy->dev, "packet length expected: %*phN\n", + dev_dbg(irtoy->dev, "packet length expected: %*phN\n", len, irtoy->in); - irtoy->state = STATE_IRDATA; - complete(&irtoy->command_done); break; } @@ -194,9 +193,6 @@ static void irtoy_response(struct irtoy *irtoy, u32 len) irtoy->tx_len -= buf_len; } break; - case STATE_COMMAND_NO_RESP: - dev_err(irtoy->dev, "unexpected response to reset: %*phN\n", - len, irtoy->in); } } From patchwork Tue Sep 14 15:18:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Young X-Patchwork-Id: 512906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 863FDC43217 for ; Tue, 14 Sep 2021 15:18:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7092861184 for ; Tue, 14 Sep 2021 15:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234817AbhINPTd (ORCPT ); Tue, 14 Sep 2021 11:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234779AbhINPTb (ORCPT ); Tue, 14 Sep 2021 11:19:31 -0400 Received: from gofer.mess.org (gofer.mess.org [IPv6:2a02:8011:d000:212::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6857BC0613C1; Tue, 14 Sep 2021 08:18:12 -0700 (PDT) Received: by gofer.mess.org (Postfix, from userid 1000) id 90BDEC65BA; Tue, 14 Sep 2021 16:18:09 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mess.org; s=2020; t=1631632689; bh=WksOAXceADQojSv7D9XcocopFCjz8Htoqezgrn7HtWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M5H+5QxlrjRGQv24cWyMdIBqxOCO7NaO8FYzva+CkR/axoNrE5Lr4uZWg8I3n8lpY oC54a1MlTaKcQOI5uPX5Fu4GnrTV/ZOxSu0UbnticgsaNCWJDSUU12HT5lErQn5JaW lkmTgwRV7bhqGFK7qqvd73/dOCSdrhfh50wQD+Xy5HCF2OUt6OVlFio+kl42YSXeFl LL+QPnkiEvOysBeaNg9kLdSrOLLJakR4k34ZT2sr1Xu5uhoS+d98nOmNptgJP1+QnO BqH0EhwgQ/oSU5PxLDV7gLe2BdqyfrAEYZCBnMjLtQAsxvmX1HgUCm17AZY8B8kGJU GA12pd5h85Plw== From: Sean Young To: linux-media@vger.kernel.org Cc: Georgi Bakalski , stable@vger.kernel.org Subject: [PATCH 4/4] media: ir_toy: prevent device from hanging during transmit Date: Tue, 14 Sep 2021 16:18:09 +0100 Message-Id: <4ed68b6848f09f191e0709702c3d1d7838a3a717.1631632442.git.sean@mess.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <22eeae667aac9d5eaaae2f21904f238ebef0c05b.1631632442.git.sean@mess.org> References: <22eeae667aac9d5eaaae2f21904f238ebef0c05b.1631632442.git.sean@mess.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org If the IR Toy is receiving IR while a transmit is done, it may end up hanging. We can prevent this from happening by re-entering sample mode just before issuing the transmit command. Link: https://github.com/bengtmartensson/HarcHardware/discussions/25 Cc: stable@vger.kernel.org Signed-off-by: Sean Young --- drivers/media/rc/ir_toy.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c index d2d9346eb8f5..71aced52248f 100644 --- a/drivers/media/rc/ir_toy.c +++ b/drivers/media/rc/ir_toy.c @@ -26,6 +26,7 @@ static const u8 COMMAND_VERSION[] = { 'v' }; // End transmit and repeat reset command so we exit sump mode static const u8 COMMAND_RESET[] = { 0xff, 0xff, 0, 0, 0, 0, 0 }; static const u8 COMMAND_SMODE_ENTER[] = { 's' }; +static const u8 COMMAND_SMODE_EXIT[] = { 0 }; static const u8 COMMAND_TXSTART[] = { 0x26, 0x24, 0x25, 0x03 }; #define REPLY_XMITCOUNT 't' @@ -317,12 +318,30 @@ static int irtoy_tx(struct rc_dev *rc, uint *txbuf, uint count) buf[i] = cpu_to_be16(v); } - buf[count] = cpu_to_be16(0xffff); + buf[count] = 0xffff; irtoy->tx_buf = buf; irtoy->tx_len = size; irtoy->emitted = 0; + // There is an issue where if the unit is receiving IR while the + // first TXSTART command is sent, the device might end up hanging + // with its led on. It does not respond to any command when this + // happens. To work around this, re-enter sample mode. + err = irtoy_command(irtoy, COMMAND_SMODE_EXIT, + sizeof(COMMAND_SMODE_EXIT), STATE_COMMAND_NO_RESP); + if (err) { + dev_err(irtoy->dev, "exit sample mode: %d\n", err); + return err; + } + + err = irtoy_command(irtoy, COMMAND_SMODE_ENTER, + sizeof(COMMAND_SMODE_ENTER), STATE_COMMAND); + if (err) { + dev_err(irtoy->dev, "enter sample mode: %d\n", err); + return err; + } + err = irtoy_command(irtoy, COMMAND_TXSTART, sizeof(COMMAND_TXSTART), STATE_TX); kfree(buf);