From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 646E648488D for ; Fri, 16 Oct 2026 16:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792168451; cv=none; b=m1Bh3KjrclLl8Y7ZqhzHUjbsVmIuDAjcOdwPcc09eUtRAVP2AiMirywtiQRLZsiv2EWOu6uuegTnCxhH2dCpXmmpoVbvk4CLvy9YiNR8uRCkfG5Qaylg9Q4/b6F5fx9tLCk/AppNjk7GS/0jaDVvQRycwXX7Afjce/MQEQQvlgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792168451; c=relaxed/simple; bh=usDo/7XNU6nwa282LnLeCFXrrSZq4xQm0JTd4N6BgvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AxG18g/NoOfy2vXWcmIT4osmDEe+Z2/JoMEzgn98zGdn+AUepv4LIW6vWnRO7PzCK0hy6ITlYxvqBgn58AcSYAaStq9gJWtC6mB/kBkFzuOaogt+AzP+NzcvCItPez6VQVobyFzycGTG4OlZKceL9pzzmxEcEir3zF3oD87JCjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gMShfoUW; arc=none smtp.client-ip=209.85.219.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gMShfoUW" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-917bab38b14so1595646d6.3 for ; Fri, 16 Oct 2026 09:34:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792168449; x=1792773249; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SfpDl7tRd49YIT38CJTAU2+wIjC5qIySjGavAzs37iQ=; b=gMShfoUWUmJJS9xaQ0lQXRpiyC4AD+VdWYl8k7H6L8o7MWjkOkhjk1bK6yXiKa5Dyf vDckAMiNx1idXk9KezO/Eqho7+2igccbIoXSS0IArIVtKYD4nE0VXHEpbWyt7YZHUxTp ZLCLXIkCaRDTPEjhm1jHEWpg9XP9oeRAjfvOlpf3gqamWgW/XkXh2BSL6ukZdZSD9ffh fZm714EJTy+60BTT5rettwyjn0H3F/1UAzF7wlSLHXMToZ2ip3fYi/IV8Jgxn+hl4stv VEnUm1iiMhyuSaxkvIX1fYOdQZxdxFkutiKD5X3IAG73JvxM8vLLN2EwjN0ORJu4M4rE Gwyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792168449; x=1792773249; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SfpDl7tRd49YIT38CJTAU2+wIjC5qIySjGavAzs37iQ=; b=uLhsQ2NHLV6XeoVrJn7ez35u/QLd+9vamGY1uP9XZtCJLFi7hiBLh/33Y2wvTMV1pf uiwO2RBtge9QKsX5SvZ5+dDAkRKI4Y59NJZhBGPztLnKc/saFcLJCDCAoJpOD3d4mu8R j6l5Gh3d2+MJQ/dumhpLhXxNkMJBhk67+XFXGOM7vQ7iCj71/Ekf8fZzqL0o/2TSYb2E PFK+2KY60CCCExrDZLPjWaABy0aWX9i4yY9if6Il3d0CDIPfTKyLl83EaCPhCbd7ZPVe gtTnYSI1erQSleNKAvds1kl8/uIhhSTiKjLT3rHFaUYSSYkCmula54JGWwafcBY5WHBx hlAQ== X-Forwarded-Encrypted: i=1; AKwUvBzLP1p9L1FhsCqwqkVun0bhx7RS9Y39uj7HBLIOZ/aCAxsevZNcsqGrovgFMpJXNPZ7xqX/oqM2Cw4hxLM=@vger.kernel.org X-Gm-Message-State: AFq9FYILhHZxtmcw2JV2MF2vV3RnHNDQy/xWIlIAMq2Vo4Jc770Dkhip l5b7PyKdDi9pV1qWsEl7QB+yZK+wBJaWrS3ntlzgWXMj/femRgf97ZOq X-Gm-Gg: AYBFou3+FjHQlSMye0Dx7qJurcijCuX23IQIHT1uwZhs9+9h08TBpfWJqm39bVlvCTr FxVeXziZ9YY+xso608KkMTtkgzYwJPHkciopBmWAB2BkO//GM8wK0cA2NE4Et6fFjZDuLWXIav7 Dim37TJPnf9l9dsN58j/KJ1oLaGkOjFd6qnh2HT96HR/03ihtNSlMUh2EKt0oMOhsqWfeky2KR4 fbQJhyAKvV7m/xGNHOhZLrSUhuf7kGVO8pjIUOVYd0+sILlX2lgMj5wa8M5OY6ntPpKAXF1O7sM lbUpZR+UUZWVFrvduduyecuVSBfj8IHnToO6E+MwsLUx01fc5AOwpqWwAwMAWzjB8SCcgMhF/v+ CKxSYJIkcF7xRMGul9IyihPE6LMPoLwIvQ6dWnczeFyY2Thfe49vSVLhpMQg+QYMlmISZF6Sozm Pu4YfhYpIGvoR2wV1QGxbZeqt8dxa8CrCJhiLAu8ShQsqUl93XieNYWrnujVOfRW0= X-Received: by 2002:ad4:5fcd:0:b0:91b:9232:2bea with SMTP id 6a1803df08f44-91bdf14dac7mr9565136d6.33.1792168449159; Fri, 16 Oct 2026 09:34:09 -0700 (PDT) Received: from beelink ([187.15.139.183]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-91bcc47bccasm25272806d6.20.2026.10.16.09.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Oct 2026 09:34:08 -0700 (PDT) From: Aldo Ariel Panzardo To: jikos@kernel.org, bentiss@kernel.org Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Aldo Ariel Panzardo Subject: [PATCH v7 1/2] HID: haptic: reorder try_module_get/get_device before input_ff_create Date: Fri, 16 Oct 2026 13:33:48 -0300 Message-ID: <20261016163349.3293666-2-qwe.aldo@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261016163349.3293666-1-qwe.aldo@gmail.com> References: <20261016151343.3120300-1-qwe.aldo@gmail.com> <20261016163349.3293666-1-qwe.aldo@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move try_module_get() and get_device() before input_ff_create() in hid_haptic_init(). The original order placed them after input_ff_create(), and failures went to input_free which called input_ff_destroy() without ever setting ret. The caller saw ret == 0 on failure and kept a dangling pointer to the haptic struct. With the references acquired first, all failure paths reach stop_buffer_free directly. The flush/event save/restore is no longer needed. Also move input_set_capability(dev, EV_FF, FF_HAPTIC) after input_ff_create() so the capability is not advertised when FF setup fails -- the caller masks the error and the input device may still be registered, where EVIOCGEFFECTS would dereference a NULL dev->ff. Fixes: 8d0bf7908b5a ("HID: multitouch: add haptic multitouch support") Cc: stable@vger.kernel.org Signed-off-by: Aldo Ariel Panzardo --- drivers/hid/hid-haptic.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c index 8760eeb..9753bbf 100644 --- a/drivers/hid/hid-haptic.c +++ b/drivers/hid/hid-haptic.c @@ -419,8 +419,6 @@ int hid_haptic_init(struct hid_device *hdev, }; const char *prefix = "hid-haptic"; char *name; - int (*flush)(struct input_dev *dev, struct file *file); - int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); haptic->hdev = hdev; haptic->max_waveform_id = max(2u, haptic->max_waveform_id); @@ -499,39 +497,36 @@ int hid_haptic_init(struct hid_device *hdev, fill_effect_buf(haptic, &stop_effect, &haptic->stop_effect, HID_HAPTIC_ORDINAL_WAVEFORMSTOP); - input_set_capability(dev, EV_FF, FF_HAPTIC); + if (!try_module_get(THIS_MODULE)) { + dev_err(&hdev->dev, "Failed to increase module count.\n"); + ret = -ENODEV; + goto stop_buffer_free; + } + if (!get_device(&hdev->dev)) { + dev_err(&hdev->dev, "Failed to get hdev device.\n"); + ret = -ENODEV; + module_put(THIS_MODULE); + goto stop_buffer_free; + } - flush = dev->flush; - event = dev->event; ret = input_ff_create(dev, FF_MAX_EFFECTS); if (ret) { dev_err(&hdev->dev, "Failed to create ff device.\n"); + put_device(&hdev->dev); + module_put(THIS_MODULE); goto stop_buffer_free; } + input_set_capability(dev, EV_FF, FF_HAPTIC); + ff = dev->ff; ff->private = haptic; ff->upload = hid_haptic_upload_effect; ff->playback = hid_haptic_playback; ff->erase = hid_haptic_erase; ff->destroy = hid_haptic_destroy; - if (!try_module_get(THIS_MODULE)) { - dev_err(&hdev->dev, "Failed to increase module count.\n"); - goto input_free; - } - if (!get_device(&hdev->dev)) { - dev_err(&hdev->dev, "Failed to get hdev device.\n"); - module_put(THIS_MODULE); - goto input_free; - } return 0; -input_free: - input_ff_destroy(dev); - /* Restore dev flush and event */ - dev->flush = flush; - dev->event = event; - return ret; stop_buffer_free: kfree(haptic->stop_effect.report_buf); haptic->stop_effect.report_buf = NULL; -- 2.53.0