From patchwork Tue Oct 3 17:31:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 820970 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="N90R46CN"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3y65gG2zrBz9sxR for ; Wed, 4 Oct 2017 04:31:36 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 57666C21F44; Tue, 3 Oct 2017 17:31:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DC6A3C21D55; Tue, 3 Oct 2017 17:31:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 93758C21D55; Tue, 3 Oct 2017 17:31:25 +0000 (UTC) Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by lists.denx.de (Postfix) with ESMTPS id 1A5DEC21C51 for ; Tue, 3 Oct 2017 17:31:24 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id w63so4736281qkd.2 for ; Tue, 03 Oct 2017 10:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/pk30owsgBDvnIXY+oOuxt97RiGnSgub3T09Vybqw4Y=; b=N90R46CNxyu7kaQULXZ7xTW+mvFScgU846+ZrzrxZuKG4t1TswnPj2CSHAMmZmoWeD ie5ykyl9OE84dwNbn4sK1lUIo0sEm8RSthOReB6thvOGleJ0ovEOHPz+Hs79+vn7b3uk RtdhhfPePwEsafvyUngZ4dR99SPXHCjHzG92D7BIWnn+wHI1z9FGvZqDeGVsw8ave+ph MEAWjQ6iDXLlehqRo7E/Kfvi+iOwAXLapcDeAz1xkn3LRNcusuRgXgA/C6UjVGJD0WAu MW/iHMk8JKaQ7pEQ2tgOc7VZXnPhwbDXUs4y7OEXggabgV/3PJBwAlhwxNrNGB5p1TDn L4nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/pk30owsgBDvnIXY+oOuxt97RiGnSgub3T09Vybqw4Y=; b=YcmGNhDYUNrJFLOswt2IFZyW+JyPZCjUSPfKoUEwScrJFi2RN5bNZrDOTFbDDfhMC3 0OMaWhuLcMfrzeL+B1fveWAfhpnXjlhXc2JWF+5nUeUhRh4bislodduV9kb7/V39gGo4 hVobME+UiYI9IRNluS4yOcur5C+SvtrRvKIQg1i1yiCwYqjEE6ZBMUBRtDUrxEXs+E+1 lJP8OADDTaB6zccc1QUneq5seV/UiQIIycHJdmGm/WVkOCP1vcE6RBfU33vFrbM/7DJT 8XxePaH38p3x700s5zDa3VCaks9/hsWuXcetNac2+BmGbC/O8mlt+erh9MLjsHbVhVEI 7xNA== X-Gm-Message-State: AMCzsaVHcypudlnkDqvCdpQPcbOGK35b0NH5/1I6Q1YNSVPc3Lf9SCzN 3Vg1EAQT0WU2G2LYcqMJziLGQgg4 X-Google-Smtp-Source: AOwi7QBThT3fZdtQBC3Csn2oSVY3JEXnEJTzBtZ1WScy2F1nTT6M1GD28QZDzQnhTvaUHpACc7YPCQ== X-Received: by 10.55.76.134 with SMTP id z128mr21476155qka.183.1507051882489; Tue, 03 Oct 2017 10:31:22 -0700 (PDT) Received: from localhost ([144.121.20.162]) by smtp.gmail.com with ESMTPSA id 16sm8502888qkd.30.2017.10.03.10.31.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2017 10:31:21 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Tue, 3 Oct 2017 13:31:14 -0400 Message-Id: <20171003173118.32645-1-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 Subject: [U-Boot] [PATCH] usb: kbd: Fix dangling pointers on probe fail X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" If probe fails, we should unregister the stdio device, else we leave dangling pointers to the parent 'struct usb_device'. Signed-off-by: Rob Clark Tested-by: Peter Robinson --- I finally got around to debugging why things explode so badly without fixing usb_kbd vs. iomux[1] (which this patch applies on top of). [1] https://patchwork.ozlabs.org/patch/818881/ common/usb_kbd.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/common/usb_kbd.c b/common/usb_kbd.c index 4c3ad95fca..82ad93f6ca 100644 --- a/common/usb_kbd.c +++ b/common/usb_kbd.c @@ -535,22 +535,40 @@ static int probe_usb_keyboard(struct usb_device *dev) error = iomux_doenv(stdin, stdinname); free(newstdin); if (error) - return error; + goto unregister_stdio; } else { /* Check if this is the standard input device. */ - if (strcmp(stdinname, DEVNAME)) - return 1; + if (strcmp(stdinname, DEVNAME)) { + error = -1; + goto unregister_stdio; + } /* Reassign the console */ - if (overwrite_console()) - return 1; + if (overwrite_console()) { + error = -1; + goto unregister_stdio; + } error = console_assign(stdin, DEVNAME); if (error) - return error; + goto unregister_stdio; } return 0; + +unregister_stdio: + /* + * If probe fails, the device will be removed.. leaving dangling + * pointers if the stdio device is not unregistered. If u-boot + * is built without stdio_deregister(), just pretend to succeed + * in order to avoid dangling pointers. + */ +#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) + stdio_deregister(DEVNAME, 1); + return error; +#else + return 0; +#endif } #ifndef CONFIG_DM_USB