Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3667037ybb; Mon, 23 Mar 2020 05:31:55 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvQeKCLTq0cWDtUvL7LfZe4/r7z4rmNLhkJ7Z2C2z0BOLPuA5LVJzJcPQ9ZXi1Lukll23aD X-Received: by 2002:a54:4594:: with SMTP id z20mr7074715oib.32.1584966715699; Mon, 23 Mar 2020 05:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584966715; cv=none; d=google.com; s=arc-20160816; b=Wy1QtIp+TnFWlR6TYCcbmLeUhF/LefjWfIbmEJjKQY7q3VLv4ddcxE1SrUoNLUG+P5 VfvScY0Er7yhXXt8fLQHNpCjGWvYPG1nSF56rycXYriQqTj4+WwPbD8UFZxDd8/+j/Fj Hf8rXrVgGjdDLilDf6697U6S4KcdlFRURBy2Xu6400HnU/HeY1oyQAojCEmhHTuxZAde Tf/j4skuFS1q3Nq7BvMnRaTpKa47Al8XVT/ZhnH2OS/shT1nUsj4KGEqCK2OBBoM+2sw 2nnkT0dM5MwQ98XQoBeW8IFQnWZy3tALtZUiAQ395ixSw5mrNL36iKyhMpOg1V1bolHE McTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=OevnXq7eEYKHASkGViX/6POF5UwCr/O5lLFLTc/N8U0=; b=yNr/aKtJwIzPukz7STLFfJt/sbqecju+5c79QFJ5U8G991W1CWlZrEV1VSU8Hcgc52 XHGGk9ndSHMP1TmiOet0USxycwpSwrd1vXwIjayGFzJZV42PW/SjUw/BGVbJ9+PHqXCz matkkwpAMcCLs0tU5VrE6F7cbJEf8mInC7FXsHGW5+NDmt0f8pAv5MTisi9TKqK0iSfv mltIOpFmjwldIvvcyrDq3b79l/M03Y1qgrPoJTWBAFsej+zlMA6FbijfM21X421DcRta NQUkqzAJcGOu/v57XO6Y1fYjtsfyNbLA4bii5QZM0kydubz9XJdckwPrlPEl3y4aucFG jxEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mHwm7rXl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14si7815025oto.47.2020.03.23.05.31.43; Mon, 23 Mar 2020 05:31:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mHwm7rXl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728226AbgCWMbR (ORCPT + 99 others); Mon, 23 Mar 2020 08:31:17 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:33775 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727548AbgCWMbR (ORCPT ); Mon, 23 Mar 2020 08:31:17 -0400 Received: by mail-pl1-f196.google.com with SMTP id g18so5873682plq.0 for ; Mon, 23 Mar 2020 05:31:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OevnXq7eEYKHASkGViX/6POF5UwCr/O5lLFLTc/N8U0=; b=mHwm7rXlDkbiGbH9lni18Ooi5wyruE2ZC8wwJTbyamVNy4cOpp1yUvUkdAJUGLwcvB gFy+MHZ6zCSRAaCGuqUImMy8HYooVqc2o0QaR0NAVOTRoi30XVq2kIZlZJm7AAFl6yNv 6sAjwJg8jiA+XwdEx91wECyX4OT8G/LUgHgCHN8yWCwTSqU/VAlx8vPx89gJGRZF+cbQ eYuQwVQnVWRVssqrWEIk8TIA5X24m8J0ZW2XxzALtFGHLIcPFdoWO4UjwPrPkUKXKg20 fvRIzwX+lULwweLUnpcwx+glP0Q5kBcpf6k6hT4NRUXBW0yJdx6FN2/J8kv1Mlqgwf8+ RT9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OevnXq7eEYKHASkGViX/6POF5UwCr/O5lLFLTc/N8U0=; b=L4hGR+n0LiJz3w38AVDb6cLrPhdfDBeI3taymNREO7ZlTh2EqDhF0gpNlGekpBxpDn 0zO0frUgUI4z/lq5SXVghgU455z/+ZDWk/7xAFvwaydCcbkQiWGGgxHS0G3uKqtp4ODP ElwwkedvHMbOkG8NGLNWuFpNEJB1W4ryuSuilNvID1TAkb8fhNRyqdDN+VHdsBeoYNtz 6VN91ucSqTYur2jU/M5MEZvYMo32RRCkZDAGNHLwChk3hrnLP17Ptv40tVqDct2iSKRu aW4hKaNVDVfbcwuFpHLae98nINbLF08/qO7q/SbqvkjRG+nxoAXE75vK5u3UguzMY/p6 5i3Q== X-Gm-Message-State: ANhLgQ0Sndu4hoXnd6EG0ZJVSgjATh5t2bxV2OG29T+Mj+feksvTGmrj mC5kXDQ3RplOs3+U2DHE5LTh X-Received: by 2002:a17:902:bc47:: with SMTP id t7mr21982260plz.47.1584966675212; Mon, 23 Mar 2020 05:31:15 -0700 (PDT) Received: from localhost.localdomain ([103.59.133.81]) by smtp.googlemail.com with ESMTPSA id 144sm3590131pgd.29.2020.03.23.05.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 05:31:14 -0700 (PDT) From: Manivannan Sadhasivam To: gregkh@linuxfoundation.org, davem@davemloft.net Cc: smohanad@codeaurora.org, jhugo@codeaurora.org, kvalo@codeaurora.org, bjorn.andersson@linaro.org, hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Manivannan Sadhasivam Subject: [PATCH v2 1/7] bus: mhi: core: Pass module owner during client driver registration Date: Mon, 23 Mar 2020 18:00:56 +0530 Message-Id: <20200323123102.13992-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323123102.13992-1-manivannan.sadhasivam@linaro.org> References: <20200323123102.13992-1-manivannan.sadhasivam@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The module owner field can be used to prevent the removal of kernel modules when there are any device files associated with it opened in userspace. Hence, modify the API to pass module owner field. For convenience, module_mhi_driver() macro is used which takes care of passing the module owner through THIS_MODULE of the module of the driver and also avoiding the use of specifying the default MHI client driver register/unregister routines. Suggested-by: Greg Kroah-Hartman Signed-off-by: Manivannan Sadhasivam --- drivers/bus/mhi/core/init.c | 5 +++-- include/linux/mhi.h | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/bus/mhi/core/init.c b/drivers/bus/mhi/core/init.c index 5fb756ca335e..eb7f556a8531 100644 --- a/drivers/bus/mhi/core/init.c +++ b/drivers/bus/mhi/core/init.c @@ -1189,7 +1189,7 @@ static int mhi_driver_remove(struct device *dev) return 0; } -int mhi_driver_register(struct mhi_driver *mhi_drv) +int __mhi_driver_register(struct mhi_driver *mhi_drv, struct module *owner) { struct device_driver *driver = &mhi_drv->driver; @@ -1197,12 +1197,13 @@ int mhi_driver_register(struct mhi_driver *mhi_drv) return -EINVAL; driver->bus = &mhi_bus_type; + driver->owner = owner; driver->probe = mhi_driver_probe; driver->remove = mhi_driver_remove; return driver_register(driver); } -EXPORT_SYMBOL_GPL(mhi_driver_register); +EXPORT_SYMBOL_GPL(__mhi_driver_register); void mhi_driver_unregister(struct mhi_driver *mhi_drv) { diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 79cb9f898544..d83e7772681b 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -514,11 +514,28 @@ int mhi_register_controller(struct mhi_controller *mhi_cntrl, */ void mhi_unregister_controller(struct mhi_controller *mhi_cntrl); +/* + * module_mhi_driver() - Helper macro for drivers that don't do + * anything special other than using default mhi_driver_register() and + * mhi_driver_unregister(). This eliminates a lot of boilerplate. + * Each module may only use this macro once. + */ +#define module_mhi_driver(mhi_drv) \ + module_driver(mhi_drv, mhi_driver_register, \ + mhi_driver_unregister) + +/* + * Macro to avoid include chaining to get THIS_MODULE + */ +#define mhi_driver_register(mhi_drv) \ + __mhi_driver_register(mhi_drv, THIS_MODULE) + /** - * mhi_driver_register - Register driver with MHI framework + * __mhi_driver_register - Register driver with MHI framework * @mhi_drv: Driver associated with the device + * @owner: The module owner */ -int mhi_driver_register(struct mhi_driver *mhi_drv); +int __mhi_driver_register(struct mhi_driver *mhi_drv, struct module *owner); /** * mhi_driver_unregister - Unregister a driver for mhi_devices -- 2.17.1