Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1552880pxb; Sat, 23 Apr 2022 09:44:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhEKNBMzRCjURlepolLvZ7QqCRYuEnDPJeO8vITwZv+ns/p9/SlAPVMqGAOLyZbCWBj3e3 X-Received: by 2002:a17:90b:1b06:b0:1d1:6633:5ec2 with SMTP id nu6-20020a17090b1b0600b001d166335ec2mr22678268pjb.103.1650732290793; Sat, 23 Apr 2022 09:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650732290; cv=none; d=google.com; s=arc-20160816; b=vO0wXjAr4sOwMeMzp9UFJ0Gqu/1gzLs9PlenjybnS9OGuRvWwEJMJmC7tuvlxayA8I xPGPtCYE/VRw0ZGQTZCdZDn/iu7lbkZVAnmidvbR2ersHwRejHyaHJyG/QV21n02wML1 qb9luiXfiVuzDRqDnmVPw//1mbfq18k8nv6Kj/CilWHWD/SRIlpulMpFHPWBhprsBmRK 8uF+UNA8LcwjyZapB102VQiOh5PMjBGPh/aU2zPmyVJdBQ2yf4ASCOc2YQ3ZHTzmWh77 zPWMxNZYJPX2bTcbaKOmkcN5sthnvn0++01p95dI9YMTaPs6+xzzlRT3J4/m1o5BOSxt xdRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=IqzEerzWLABZb+iaArImvfubeSzbeeC6t3f7w2iOtok=; b=LFiGv3FGEsN887xzwzAPSyDCY2b79GppvYMKCoWMcveunJInT2VSzVKhKN/6o/JI3Z 6JpTQXp/nYncHWc3X1zBuON+AmNc2y0Rx5Ah1RJOf3S6QAzbGR/Il8N0fD+hmaAue7Tj FDUwsgJxzvyZqSJt2Yme/mER7ARtxXhiBE7dC1muSmQyt4eya5cawzdG2HgCB4nRX5Yq csWf7qrfAYdK5R2ap+THyNjwFMHxgt6pon2m5Xy1BRjcf9+MtC48fqNhcHI16tgOdC8m bYXhBrclheRTit4kBlEPxmAw/A2pyOLBZCNR7eoNM1LPdbgfXGyz+YminZJuIj16Sk6i EB3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EtShkVoz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z10-20020a170902d54a00b00154a965e488si11393289plf.237.2022.04.23.09.44.34; Sat, 23 Apr 2022 09:44:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EtShkVoz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235196AbiDWLom (ORCPT + 99 others); Sat, 23 Apr 2022 07:44:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235072AbiDWLok (ORCPT ); Sat, 23 Apr 2022 07:44:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CCFC18364 for ; Sat, 23 Apr 2022 04:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650714101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IqzEerzWLABZb+iaArImvfubeSzbeeC6t3f7w2iOtok=; b=EtShkVozwmp4KTif6VBOg0WYMnbqd6ZvfnPXyCYJbjlXnuh1/zi0uBpzr8Zr78xv2vCPRA TkFKWeEs3p6ZmQNyTiKTUurpBwDc9zm5smAhbXTdEGwBRItBq8svyXb0RQed1gRZA+TLhW QWQmLL+hvYPvmYeDL8K+woK5P465yTs= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-0vRaFlwCMnq3jgueq18GiA-1; Sat, 23 Apr 2022 07:41:33 -0400 X-MC-Unique: 0vRaFlwCMnq3jgueq18GiA-1 Received: by mail-ed1-f69.google.com with SMTP id eg38-20020a05640228a600b00425d61d0302so372772edb.17 for ; Sat, 23 Apr 2022 04:41:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=IqzEerzWLABZb+iaArImvfubeSzbeeC6t3f7w2iOtok=; b=gAdS+xFziFbtjhHGzEAAvskATKGh4QsNlTrIdMJLrNniFmlC0he+ZwJXMXI46qsYlW w62xsbOPDRmC8zvcpyVz2XEfj3X4q1XsYbrBfgJtw4qSKk87vyu6USyksDOIqxR3Wgik yrKDOY4B0ZDxmRsB3RV1UM6wqtfBLEji+m8BFJbzH6pFvfjPKB6GLd6Za8XrdKwHkoM6 9oSKQmQ2O95aja/ZSYFvkf6giMafOk9ow+lB23k6jFms5bvCIOmj7hWS1YesGNr3wv6N IgV87sR0LfeXsLSSVJfw38K8l3C6XVCy/3ZQUSZXN4LlpdeqEGQ/HrwpCTT9XbPRS8uz V7tw== X-Gm-Message-State: AOAM532Lbt6TIJI1AeqGDkc4LvqrQZNbV4LYpTI2DWUZICW8i1NxuUSe 7PwOktwToKHNmLoVNKR0nwvqAXQgpOi4s0HzLcJ1kXi18a2lgD9m7dtKVA0O7R+kFf1juU72uR1 9oiWRZfe8+QJWLiiJfhIPNVTp X-Received: by 2002:aa7:d393:0:b0:425:a8f8:663a with SMTP id x19-20020aa7d393000000b00425a8f8663amr9604018edq.323.1650714091955; Sat, 23 Apr 2022 04:41:31 -0700 (PDT) X-Received: by 2002:aa7:d393:0:b0:425:a8f8:663a with SMTP id x19-20020aa7d393000000b00425a8f8663amr9604008edq.323.1650714091787; Sat, 23 Apr 2022 04:41:31 -0700 (PDT) Received: from ?IPV6:2001:1c00:c1e:bf00:d69d:5353:dba5:ee81? (2001-1c00-0c1e-bf00-d69d-5353-dba5-ee81.cable.dynamic.v6.ziggo.nl. [2001:1c00:c1e:bf00:d69d:5353:dba5:ee81]) by smtp.gmail.com with ESMTPSA id v21-20020a1709064e9500b006e8973a14d0sm1617204eju.174.2022.04.23.04.41.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 23 Apr 2022 04:41:31 -0700 (PDT) Message-ID: <876f7c92-4e50-401e-f0b0-c2942bd8b63d@redhat.com> Date: Sat, 23 Apr 2022 13:41:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH 2/3] HID: logitech-hidpp: Fix double free on managed resource Content-Language: en-US To: =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= , hadess@hadess.net Cc: dmitry.torokhov@gmail.com, rydberg@bitmath.org, lains@riseup.net, jikos@kernel.org, benjamin.tissoires@redhat.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220422161709.30198-1-jose.exposito89@gmail.com> <20220422161709.30198-2-jose.exposito89@gmail.com> From: Hans de Goede In-Reply-To: <20220422161709.30198-2-jose.exposito89@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 4/22/22 18:17, José Expósito wrote: > As described in the documentation for devm_input_allocate_device(): > > Managed input devices do not need to be explicitly unregistered or > freed as it will be done automatically when owner device unbinds from > its driver (or binding fails). > > However this driver was explicitly freeing the input device, allocated > using devm_input_allocate_device() through hidpp_allocate_input(). > > Remove the call to input_free_device() to avoid a possible double free > error. Actually calling input_free_device() on a devm allocated input device is fine. The input subsystem has chosen to not have a separate devm_input_free_device(), instead input_free_device() knows if a device is allocated through devm and then also frees the devres tied to it: void input_free_device(struct input_dev *dev) { if (dev) { if (dev->devres_managed) WARN_ON(devres_destroy(dev->dev.parent, devm_input_device_release, devm_input_device_match, dev)); input_put_device(dev); } } > > Fixes: c39e3d5fc9dd3 ("HID: logitech-hidpp: late bind the input device on wireless connection") > Signed-off-by: José Expósito > --- > drivers/hid/hid-logitech-hidpp.c | 6 +----- > 1 file changed, 1 insertion(+), 5 deletions(-) > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c > index 81de88ab2ecc..9c00a781ab57 100644 > --- a/drivers/hid/hid-logitech-hidpp.c > +++ b/drivers/hid/hid-logitech-hidpp.c > @@ -3957,11 +3957,7 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) > } > > hidpp_populate_input(hidpp, input); > - > - ret = input_register_device(input); > - if (ret) > - input_free_device(input); > - The original code does look wrong there though, since the input device is free-ed it should not be stored in hidpp->delayed_input, so this should be comes: ret = input_register_device(input); if (ret) { input_free_device(input); return; } Regards, Hans > hidpp->delayed_input = input; > } >