Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp153620pxj; Mon, 17 May 2021 23:43:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7XDtEc+e0RKmYzNz9B1kSARINFDSlcjquWZWXcPHy8lGF9kQn/aQ/5GixmI4Ifep4Wz7B X-Received: by 2002:a50:9e63:: with SMTP id z90mr5251140ede.342.1621320192242; Mon, 17 May 2021 23:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621320192; cv=none; d=google.com; s=arc-20160816; b=KNKkpL1BN+GmWG9NO3MI97RA/sbZO4avC6MJ/sGKIBHPW2F9ohVESfPj8KRAmSR4UA LF492bEB1viPmhUv5LGsaCq0C5UO+KoF0/v+9mpRi1X9yZ+Wrm3JsbUjyW5DhsLBZq9z RhLl5XIf/R8iE2fyt2ud8JjXRlhJ0tzn+Nnpa9/Cm+PDft80ALZKyfp/bLmRsNPs+JWO mvwHUHHMNC0DYsOWChE+4nwrb2yhT11rIUShs2pI9OPLrasd1Et5IJqP6gyzVy+iUORn HkXaS8A4ER12aWoaF4BY/0HmGByH8urm4Hk8FfIlBOSiexn4iWuMjVrUf9gt+q0ftmJ2 lgew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x3PPnNiQXnUEPFHtitlBpiL/qwpSH3623Et6BGuuF7M=; b=gohgA7X1JrjueXsQh24CLfjQdKbOv0Cf3FRmUQsMn90DGHMeV7WgMAKFQyRFuOjeQI li5nu7wV7Ij6JNLFThp/b4n6SfBvJoMeW73P1i5Cz2pi3W3KQJzh58pwVIts7ITowOJ3 lR6XR7hF/H9yrfWyPxvROM3mu5RoA+/V4DmPL4MTQBKbXERMYL3MxEfWv++b7qQN/OBf nppjoyqXIaFWoTlJpGCaJOnDFI42v9yJosYD/E9HJsHZUnZDXGe3sC7n6yRLA2QjVYEc 25zgiyWBZ5/jRz8kMz3klQh5RfCDj4gYOVo752BJBYhXpTkDkaZa19dFFy1Z0Awftbtj Uy+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J7HnSsPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si7599246edt.165.2021.05.17.23.42.49; Mon, 17 May 2021 23:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J7HnSsPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241718AbhEQOwT (ORCPT + 99 others); Mon, 17 May 2021 10:52:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:56730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241296AbhEQOoW (ORCPT ); Mon, 17 May 2021 10:44:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D17F761955; Mon, 17 May 2021 14:20:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261236; bh=XR2uOFFXND4OXxNyR95eOdKZs4Yb3E4Yj2In+6DR7Pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J7HnSsPVdCMj4ZlKlE//rWGndx+IRJMh8353PXbf747LL1/ms2MJE1fxCZLNDZh1Q U2LjAfYB1d+Mh07XPQ7EuFBUKuFsbTtAg8rTpEAo1Xb/CfZJObNoT494KpEk19lwCM zL+Z8Li3M3jDVJsrOsKSKZAWixk3CatD/JqdjhCM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tomasz Duszynski , Alexandru Ardelean , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.12 323/363] iio: core: fix ioctl handlers removal Date: Mon, 17 May 2021 16:03:09 +0200 Message-Id: <20210517140313.519198043@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tomasz Duszynski commit 901f84de0e16bde10a72d7eb2f2eb73fcde8fa1a upstream. Currently ioctl handlers are removed twice. For the first time during iio_device_unregister() then later on inside iio_device_unregister_eventset() and iio_buffers_free_sysfs_and_mask(). Double free leads to kernel panic. Fix this by not touching ioctl handlers list directly but rather letting code responsible for registration call the matching cleanup routine itself. Fixes: 8dedcc3eee3ac ("iio: core: centralize ioctl() calls to the main chardev") Signed-off-by: Tomasz Duszynski Acked-by: Alexandru Ardelean Cc: Link: https://lore.kernel.org/r/20210423080244.2790-1-tomasz.duszynski@octakon.com Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/industrialio-core.c | 6 ------ 1 file changed, 6 deletions(-) --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1863,9 +1863,6 @@ EXPORT_SYMBOL(__iio_device_register); **/ void iio_device_unregister(struct iio_dev *indio_dev) { - struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); - struct iio_ioctl_handler *h, *t; - cdev_device_del(&indio_dev->chrdev, &indio_dev->dev); mutex_lock(&indio_dev->info_exist_lock); @@ -1876,9 +1873,6 @@ void iio_device_unregister(struct iio_de indio_dev->info = NULL; - list_for_each_entry_safe(h, t, &iio_dev_opaque->ioctl_handlers, entry) - list_del(&h->entry); - iio_device_wakeup_eventset(indio_dev); iio_buffer_wakeup_poll(indio_dev);