From patchwork Sat Apr 1 18:42:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9658191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8265860351 for ; Sat, 1 Apr 2017 18:43:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BFB028577 for ; Sat, 1 Apr 2017 18:43:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D156285A9; Sat, 1 Apr 2017 18:43:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B95128577 for ; Sat, 1 Apr 2017 18:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751856AbdDASm6 (ORCPT ); Sat, 1 Apr 2017 14:42:58 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35910 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751733AbdDASm5 (ORCPT ); Sat, 1 Apr 2017 14:42:57 -0400 Received: by mail-pg0-f67.google.com with SMTP id 81so22834747pgh.3; Sat, 01 Apr 2017 11:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=wbVuRYyT9Oe834L2DT/J9EcJkRb/1BzOm5JGE0990mA=; b=Kdbz+RvnYbsXd70FjtSNuMtZkjoNyMcANb19gvGqD/313tPd2U52mVoxoDzjDhM+wK +DcpQdByCytU6e1eKLaDKb23y3s8R/5Ij8Jy7FBIyqzQuZ0rw7l3icFl1LdZQ8KHb36R 6IrMNOzFiO4gXKnt47o0YQCeOGZgcpc/7s0i9MBFjMk4CTYvnhd6c+zicirn7Y/GkOQ2 jELO3UTcoL9qZaADymfYaHw3pcyWcuhcaWCIFsbDXN3rNocdtJZ8+EDkPc/mW8zKuov4 +j8bJ3yTQiDTdfDbjE+L4n/LSKS1/3tUkoMI2pisH/oxA3b9mGp/2XPUIoLoYJuhNC+r /XQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=wbVuRYyT9Oe834L2DT/J9EcJkRb/1BzOm5JGE0990mA=; b=XueH5IsJQX6nzcUG9JaYG5x3RzfNrJxsF99uKhwNnkwOHnQ0dfAX5L3DF0Wji5oKBq rLAVr1EUj4zOcn67rh7sjEprl/yNFkfXGgIJpQTANZlEvndJmaOyM6BF0CDPo1Kmxuj9 K96KW09H1BjVsNvsxGZoJ51Kp5PMAQIuhCfRAvHhEBsiATkiyfyezOkbSP8UTD8g1rhE 9+c1OxHex/PPEB6QXEejg3oVNw5tlAyDrK6i6MNpquaSTZF0dwcM+7PcI9NhENtqppT4 ATz+NLTQDbYEIL/rl0oEgp2YuX3rLjG27aX5l5tVZVtfAcITBvrSjE7eqggMiz3mYsrV 8VIA== X-Gm-Message-State: AFeK/H3spd8J0sROmtcWkqAu+o8a1bqbd1YWkbmkxm+92AbX+IkLI1sLAzJzhvnKC9OeJg== X-Received: by 10.99.156.2 with SMTP id f2mr9295913pge.189.1491072176862; Sat, 01 Apr 2017 11:42:56 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1311:6969:12b1:751a:a966]) by smtp.gmail.com with ESMTPSA id n185sm17272655pga.9.2017.04.01.11.42.56 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sat, 01 Apr 2017 11:42:56 -0700 (PDT) Date: Sat, 1 Apr 2017 11:42:54 -0700 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Benjamin Tissoires , linux-kernel@vger.kernel.org Subject: [PATCH] Input: psmouse - fix cleaning up SMBus companions Message-ID: <20170401184254.GA13949@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When trying to destroy platform data after destruction of SMbus companion, we need to make sure that we are actually dealing with an SMB companion device, and not some random I2C client device. Fixes: 8eb92e5c9133 ("Input: psmouse - add support for SMBus companions") Reported-by: Benjamin Tissoires Signed-off-by: Dmitry Torokhov Tested-by: Benjamin Tissoires --- drivers/input/mouse/psmouse-smbus.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/input/mouse/psmouse-smbus.c b/drivers/input/mouse/psmouse-smbus.c index d0cf2fde173e..c7ac24d119c1 100644 --- a/drivers/input/mouse/psmouse-smbus.c +++ b/drivers/input/mouse/psmouse-smbus.c @@ -61,24 +61,29 @@ static void psmouse_smbus_check_adapter(struct i2c_adapter *adapter) static void psmouse_smbus_detach_i2c_client(struct i2c_client *client) { - struct psmouse_smbus_dev *smbdev; + struct psmouse_smbus_dev *smbdev, *tmp; mutex_lock(&psmouse_smbus_mutex); - list_for_each_entry(smbdev, &psmouse_smbus_list, node) { - if (smbdev->client == client) { + list_for_each_entry_safe(smbdev, tmp, &psmouse_smbus_list, node) { + if (smbdev->client != client) + continue; + + kfree(client->dev.platform_data); + client->dev.platform_data = NULL; + + if (!smbdev->dead) { psmouse_dbg(smbdev->psmouse, "Marking SMBus companion %s as gone\n", dev_name(&smbdev->client->dev)); - smbdev->client = NULL; smbdev->dead = true; serio_rescan(smbdev->psmouse->ps2dev.serio); + } else { + list_del(&smbdev->node); + kfree(smbdev); } } - kfree(client->dev.platform_data); - client->dev.platform_data = NULL; - mutex_unlock(&psmouse_smbus_mutex); } @@ -162,17 +167,20 @@ static void psmouse_smbus_disconnect(struct psmouse *psmouse) struct psmouse_smbus_dev *smbdev = psmouse->private; mutex_lock(&psmouse_smbus_mutex); - list_del(&smbdev->node); - mutex_unlock(&psmouse_smbus_mutex); - if (smbdev->client) { + if (smbdev->dead) { + list_del(&smbdev->node); + kfree(smbdev); + } else { + smbdev->dead = true; psmouse_dbg(smbdev->psmouse, "posting removal request for SMBus companion %s\n", dev_name(&smbdev->client->dev)); psmouse_smbus_schedule_remove(smbdev->client); } - kfree(smbdev); + mutex_unlock(&psmouse_smbus_mutex); + psmouse->private = NULL; }