Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp431581iob; Wed, 18 May 2022 05:29:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBahVVJ71L7Oz0nZ38yx0Bwvd8O6DRY78xORGvKPZdYv6twetAAQot3zUnIoKpNjBIXPWJ X-Received: by 2002:a17:90b:4f46:b0:1dd:2ddd:daff with SMTP id pj6-20020a17090b4f4600b001dd2ddddaffmr42061472pjb.177.1652876948153; Wed, 18 May 2022 05:29:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652876948; cv=none; d=google.com; s=arc-20160816; b=yUyhl2M9hz1n7VFWaRZIyqUo3MzaSxPUH8wRQyhAQILZWUpOsyIKPZYJkynZeM/rsP dWC45sQVlLnCMYGQul78Uc+IbzCWt8MSrKlnhaYM/oKnFP6vD/2CxbBZJug4Hh3qsf1V 71dkQnFl+OABA39rYhPSGTF+gbuFUITY5o9eu7DFPcy3dG9y1DYJm6JQsy57fXULusKO wUWTMSVAHC6X6gIlbAy7eGK9wHHCUmj5xPPKuiMrMIbpRKMc8JhHr4L5LGAPN3/Gxfba 4uCu2zUE+ndcYc85kT8688XtYQ53OvY86IupvqJf/yMkeEeZLKjMP2VxWvf4zJ875xWb 9aiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=sFH5idW86lWQdWvgqVFesZuStLdWb38v0wu7UBLxe5s=; b=BSzReJh2Fixy3u2L44RKuiGiO/xxGwqQbO3QJkzc2qfoA0YWp7fl5KDVsaXLdpml5W Ht6Z/dQoHXX3RU7mw/DdpOhwz/nu/biG93pDqdES6pUAREUwR/D4hTySC3tB2B72fx2R JNLnzFcRwvJj/hj5CIKIvU+fc4Qofsgi+GwbR9MIn4cc8zOE+lzX8E8d/K4UjlhaYJi0 6LeyLKxjx0O0fRZp9KgizuOhNnTsUZZo6D/8oCaKza7AuYG//Q83RncDNu2P4+CABFUg wRe0eF0ZgCMU3QHSdgic7MO7ZbKevx2001ZydT23XXmUDgIB//4Fhcbp9Fl+jwaJ5jR7 6sRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=hZpoRYai; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c2-20020a630d02000000b003c1e24ba350si2310867pgl.786.2022.05.18.05.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 05:29:08 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=hZpoRYai; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6A2096350A; Wed, 18 May 2022 05:26:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236394AbiERM00 (ORCPT + 99 others); Wed, 18 May 2022 08:26:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236527AbiERM0X (ORCPT ); Wed, 18 May 2022 08:26:23 -0400 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E6FD5FF0D; Wed, 18 May 2022 05:26:18 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id 3618C5FD02; Wed, 18 May 2022 15:26:15 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1652876775; bh=sFH5idW86lWQdWvgqVFesZuStLdWb38v0wu7UBLxe5s=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=hZpoRYairtXzQsb9c6qOeMBgrb8K9oiH3VkZuemIMBxs5nKXZXTdbtviPfb4H5iZE 1U0jaQnb83VUKUBQrSJ19/alHHVHqV++bFrralWmYqg5pC6/+By+OCM+KRdx5F/jkq 5U6WeMTFmEx093VTdDHbY4mxBSsMCXzi9rh0nZAyuWOIABJHJ5I1WGuOkkVMkF3kxd N2TM1n4NBzCjPvQg+00dPGlr3QoouZP0DwTLkblzcc8YCQNeIUSioAPg4fQcY2Ib83 +3HyBTbeTVSXF6eRzTQidNzeojsVWkpD1EeQkADFk9vOOe22JdXGsQgybKEufKQMqr lb3sR67M5lemA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Wed, 18 May 2022 15:26:13 +0300 (MSK) From: Dmitry Rokosov To: Jonathan Cameron CC: "robh+dt@kernel.org" , "stano.jakubek@gmail.com" , "shawnguo@kernel.org" , "jic23@kernel.org" , "lars@metafoo.de" , "andy.shevchenko@gmail.com" , "stephan@gerhold.net" , "linux-iio@vger.kernel.org" , "devicetree@vger.kernel.org" , kernel , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v1 2/3] iio: add MEMSensing MSA311 3-axis accelerometer driver Thread-Topic: [PATCH v1 2/3] iio: add MEMSensing MSA311 3-axis accelerometer driver Thread-Index: AQHYVASOybrxT0DjfUWoYWuGUlWOX6z4bouAgAnb/gCAIkALgA== Date: Wed, 18 May 2022 12:25:59 +0000 Message-ID: <20220518122515.aby5lbb4xusr6pdt@CAB-WSD-L081021.sigma.sbrf.ru> References: <20220419154555.24191-1-ddrokosov@sberdevices.ru> <20220419154555.24191-3-ddrokosov@sberdevices.ru> <20220420115023.00006a25@Huawei.com> <20220426172406.s4h6g7nrpytaq263@CAB-WSD-L081021.sigma.sbrf.ru> In-Reply-To: <20220426172406.s4h6g7nrpytaq263@CAB-WSD-L081021.sigma.sbrf.ru> Accept-Language: ru-RU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/05/18 09:28:00 #19466841 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Jonathan, I have two items to be discussed about iio_trigger_get(). Please see my questions below and correct me if I'm wrong. On Tue, Apr 26, 2022 at 08:24:10PM +0300, Dmitry Rokosov wrote: > > > + "%s-new-data", > > > + indio_dev->name); > > > + if (!msa311->new_data_trig) { > > > + dev_err(&i2c->dev, "cannot allocate new data trig\n"); > > > + err =3D -ENOMEM; > > > + goto err_lock_destroy; > > > + } > > > + > > > + msa311->new_data_trig->dev.parent =3D &i2c->dev; > > > + msa311->new_data_trig->ops =3D &msa311_new_data_trig_ops; > > > + iio_trigger_set_drvdata(msa311->new_data_trig, indio_dev); > > > + indio_dev->trig =3D msa311->new_data_trig; > >=20 > > This will create a double free if you were to change the trigger. > > indio_dev->trig =3D iio_trigger_get(trig); > >=20 >=20 > I didn't take into account other trigger usage. > I'll rework this place for the v2. >=20 The first one problem is module_get() calling for trigger get() semantic. I've applied iio_trigger_get() function to acquire module refcnt, but I've faced with rmmod busy problem. IIO driver module doesn't want to stop and unload due to not having zero module refcnt. Syscall delete_module() tries to stop module first and after calls driver exit() function (which executes devm_* handlers inside, including II= O trigger unregister). It means we have the chicken or the egg dilemma here. Module can't be unloaded until module refcnt is not zero and we can't execute IIO trigger unregister (decrease module refcnt) only when module refcnt is zero. I suppose the possible solution to such a problem is a different semantic for internal triggers (inside driver itself) and external drivers (like hwtimer trigger). What do you think? The second one issue is located in the different IIO drivers. Some modules call iio_trigger_get() before iio_trigger_register(), trig->owner is not initialized to the right value (THIS_MODULE) and we don't acquire refcnt for proper driver object. I'm going to send patchset to problem driver set, but I can test only buildable status for such modules, are you okay with that? --=20 Thank you, Dmitry