From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92150C43334 for ; Thu, 30 Jun 2022 13:48:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235074AbiF3NsI (ORCPT ); Thu, 30 Jun 2022 09:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235334AbiF3NsB (ORCPT ); Thu, 30 Jun 2022 09:48:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62AC52F01A; Thu, 30 Jun 2022 06:47:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A536861FF5; Thu, 30 Jun 2022 13:47:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A52CFC34115; Thu, 30 Jun 2022 13:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656596876; bh=bcYax/XTkTxuUBkyvxRtU6WAcPJpxGL8e0zlBGGR3rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TKNHOMV5AWijeysoP3Qg+2bUPr1KLKYQr24yHW/cgf8ZaGlwtDYdsiLlj2BvFQktj ECiLzvz8TNORp4gvrbDh3GiSk/U4WqB1LxDsKvoI+E6OIDPLaBCoMm499f9BDcio4t 4nKsVC4KJE6Im+x/aQhusLwYDc3zWCVFWsBbjN/0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Rokosov , Andy Shevchenko , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.9 13/29] iio:accel:bma180: rearrange iio trigger get and register Date: Thu, 30 Jun 2022 15:46:13 +0200 Message-Id: <20220630133231.595556846@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220630133231.200642128@linuxfoundation.org> References: <20220630133231.200642128@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: stable@vger.kernel.org From: Dmitry Rokosov commit e5f3205b04d7f95a2ef43bce4b454a7f264d6923 upstream. IIO trigger interface function iio_trigger_get() should be called after iio_trigger_register() (or its devm analogue) strictly, because of iio_trigger_get() acquires module refcnt based on the trigger->owner pointer, which is initialized inside iio_trigger_register() to THIS_MODULE. If this call order is wrong, the next iio_trigger_put() (from sysfs callback or "delete module" path) will dereference "default" module refcnt, which is incorrect behaviour. Fixes: 0668a4e4d297 ("iio: accel: bma180: Fix indio_dev->trig assignment") Signed-off-by: Dmitry Rokosov Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/20220524181150.9240-2-ddrokosov@sberdevices.ru Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/accel/bma180.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/iio/accel/bma180.c +++ b/drivers/iio/accel/bma180.c @@ -776,11 +776,12 @@ static int bma180_probe(struct i2c_clien data->trig->dev.parent = &client->dev; data->trig->ops = &bma180_trigger_ops; iio_trigger_set_drvdata(data->trig, indio_dev); - indio_dev->trig = iio_trigger_get(data->trig); ret = iio_trigger_register(data->trig); if (ret) goto err_trigger_free; + + indio_dev->trig = iio_trigger_get(data->trig); } ret = iio_triggered_buffer_setup(indio_dev, NULL,