From patchwork Tue May 22 20:10:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Rivas Costa X-Patchwork-Id: 10419559 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 EAAF36032A for ; Tue, 22 May 2018 20:10:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA2132901B for ; Tue, 22 May 2018 20:10:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC81B29033; Tue, 22 May 2018 20:10:29 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 79DA12901B for ; Tue, 22 May 2018 20:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbeEVUKQ (ORCPT ); Tue, 22 May 2018 16:10:16 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:39505 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752634AbeEVUKP (ORCPT ); Tue, 22 May 2018 16:10:15 -0400 Received: by mail-wm0-f65.google.com with SMTP id f8-v6so3087898wmc.4; Tue, 22 May 2018 13:10:14 -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=98nLuVocHz969mHxUn47ik0FMcaW2a8uZGMKqoFJLuM=; b=JfCwJ6B35gTruDYZ+Nwvtbq/USwFWLqiNaeehvFXj4okRhSzXdwt93RkbjcLw8dqvc dW44bVynHr9IcIwxSr7Oef6d5v3QlYbi0kYV9naRkFEDe3/g3zsXSqdgn0DXGf615lR6 GMeucoBsTM39DhXzzJlWMVLQ8/F4sW180aZxl8c9CD1UFj71Svvgsmb88891IOU00gBB kUofmbOu1++PRu2JNn32i8fMhqXebHjgAwFCYyMjV8N/VovIPTpMMvaadhFHtIViXXl4 xe/fBPF089crY1Ay6omnCNuCfYqTvyyEXy69jUfoI+9YuEJbHX8F3DQz58I9FAvuDiNQ PZbw== 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=98nLuVocHz969mHxUn47ik0FMcaW2a8uZGMKqoFJLuM=; b=FN+U3w+RNe1m8bdTOu5VSm4yJUChqzE8d5QkFtM9bMXsKJoyj7R0kYdO30gwhoG/Pf L50jvhyqAjBJPuJBxRdhY/kMkTIkVmN89OYFqiboU/kof7VjmX8PU6AfO63yg9yuf3i7 ryr9Ga6pMjqd1xgEFCefdgfadZ8Vv+ZsPzpY8rAUAfH3FFkWB3Avg6wGmWcrlsx95n/n gUdSzXQHZwLuqr89lIAXRaznp0rkIVjmjze2VwSLWiQnB4MhRppAqR34lxK/5JGCld5A OV5a+YJk9k5//u9rIQTe/dBZJjsP032hTPSWS8N1N9sNZWXVrML8wdLPQxKDtsDD1FC3 YhGw== X-Gm-Message-State: ALKqPwfDzudCAbeqOWpbfX6rSFbIlT7XU7CjyKYVeJ2ghF+t3+MH3Xw/ EWjzLo3U2bLpXkkmcbJUqKk= X-Google-Smtp-Source: AB8JxZp5ldCXhs5K+6w/ZVMKpha+lXtVUIG6oJNIVeYbOiW/mspREQIZeqLeTtKTeS9oi+3KJzDxqg== X-Received: by 2002:a1c:c46:: with SMTP id 67-v6mr2440583wmm.79.1527019813749; Tue, 22 May 2018 13:10:13 -0700 (PDT) Received: from localhost.localdomain ([2a01:c50e:5126:7a00:fd77:f3c4:9540:ea56]) by smtp.gmail.com with ESMTPSA id p189-v6sm769624wmg.18.2018.05.22.13.10.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 13:10:12 -0700 (PDT) From: Rodrigo Rivas Costa To: Jiri Kosina , Benjamin Tissoires , "Pierre-Loup A. Griffais" , =?UTF-8?q?Cl=C3=A9ment=20VUCHENER?= , lkml , linux-input Cc: Rodrigo Rivas Costa Subject: [PATCH] HID: steam: use hid_device.driver_data instead of hid_set_drvdata() Date: Tue, 22 May 2018 22:10:06 +0200 Message-Id: <20180522201006.14003-1-rodrigorivascosta@gmail.com> X-Mailer: git-send-email 2.17.0 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 creating the low-level hidraw device, the reference to steam_device was stored using hid_set_drvdata(). But this value is not guaranteed to be kept when set before calling probe. If this pointer is reset, it crashes when opening the emulated hidraw device. It looks like hid_set_drvdata() is for users "avobe" this hid_device, while hid_device.driver_data it for users "below" this one. In this case, we are creating a virtual hidraw device, so we must use hid_device.driver_data. Signed-off-by: Rodrigo Rivas Costa Tested-by: Mariusz Ceier --- This patch is to be applied over hid/for-4.18/hid-steam. Is this the proper way to signal it? I don't know exactly when the problem started. I am pretty sure that it worked with 4.16.2, but it failed with 4.16.9. Or maybe it is caused by upgrading the firmware of the controller, although the protocol seems identical. drivers/hid/hid-steam.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c index cb86cc834201..0422ec2b13d2 100644 --- a/drivers/hid/hid-steam.c +++ b/drivers/hid/hid-steam.c @@ -573,7 +573,7 @@ static bool steam_is_valve_interface(struct hid_device *hdev) static int steam_client_ll_parse(struct hid_device *hdev) { - struct steam_device *steam = hid_get_drvdata(hdev); + struct steam_device *steam = hdev->driver_data; return hid_parse_report(hdev, steam->hdev->dev_rdesc, steam->hdev->dev_rsize); @@ -590,7 +590,7 @@ static void steam_client_ll_stop(struct hid_device *hdev) static int steam_client_ll_open(struct hid_device *hdev) { - struct steam_device *steam = hid_get_drvdata(hdev); + struct steam_device *steam = hdev->driver_data; int ret; ret = hid_hw_open(steam->hdev); @@ -605,7 +605,7 @@ static int steam_client_ll_open(struct hid_device *hdev) static void steam_client_ll_close(struct hid_device *hdev) { - struct steam_device *steam = hid_get_drvdata(hdev); + struct steam_device *steam = hdev->driver_data; mutex_lock(&steam->mutex); steam->client_opened = false; @@ -623,7 +623,7 @@ static int steam_client_ll_raw_request(struct hid_device *hdev, size_t count, unsigned char report_type, int reqtype) { - struct steam_device *steam = hid_get_drvdata(hdev); + struct steam_device *steam = hdev->driver_data; return hid_hw_raw_request(steam->hdev, reportnum, buf, count, report_type, reqtype); @@ -710,7 +710,7 @@ static int steam_probe(struct hid_device *hdev, ret = PTR_ERR(steam->client_hdev); goto client_hdev_fail; } - hid_set_drvdata(steam->client_hdev, steam); + steam->client_hdev->driver_data = steam; /* * With the real steam controller interface, do not connect hidraw.