From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752545AbcL0IcZ (ORCPT ); Tue, 27 Dec 2016 03:32:25 -0500 Received: from fllnx209.ext.ti.com ([198.47.19.16]:44497 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbcL0Ib7 (ORCPT ); Tue, 27 Dec 2016 03:31:59 -0500 Subject: Re: [PATCH] phy: core: check whether ops callback function is assigned To: Jaehoon Chung , References: <20161222094222.6871-1-jh80.chung@samsung.com> From: Kishon Vijay Abraham I Message-ID: <586226F8.7010604@ti.com> Date: Tue, 27 Dec 2016 14:01:52 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <20161222094222.6871-1-jh80.chung@samsung.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thursday 22 December 2016 03:12 PM, Jaehoon Chung wrote: > If some ops-> callback function are not assigend, then it should do the > unexpect behavior. > To prevent the potential NULL pointer dereference, check the each > callback functions before doing operation. The call backs checks are done after the mutex. Moreover even if the call backs are not assigned, the user can call the phy ops for doing pm_runtime. Thanks Kishon > > Signed-off-by: Jaehoon Chung > --- > drivers/phy/phy-core.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c > index a268f4d6f3e9..e4eb4431c8a4 100644 > --- a/drivers/phy/phy-core.c > +++ b/drivers/phy/phy-core.c > @@ -219,7 +219,7 @@ int phy_init(struct phy *phy) > { > int ret; > > - if (!phy) > + if (!phy || !phy->ops->init) > return 0; > > ret = phy_pm_runtime_get_sync(phy); > @@ -248,7 +248,7 @@ int phy_exit(struct phy *phy) > { > int ret; > > - if (!phy) > + if (!phy || !phy->ops->exit) > return 0; > > ret = phy_pm_runtime_get_sync(phy); > @@ -277,7 +277,7 @@ int phy_power_on(struct phy *phy) > { > int ret = 0; > > - if (!phy) > + if (!phy || !phy->ops->power_on) > goto out; > > if (phy->pwr) { > @@ -319,7 +319,7 @@ int phy_power_off(struct phy *phy) > { > int ret; > > - if (!phy) > + if (!phy || !phy->ops->power_off) > return 0; > > mutex_lock(&phy->mutex); >