Re: [PATCH 1/1] net: hns: avoid null pointer dereference
From: Heinrich SchuchardtDate: Tue, 17 May 2016 22:01:15 +0200 > In the statement > assert(priv || priv->ae_handle); > the right side of || is only evaluated if priv is null. > > Signed-off-by: Heinrich Schuchardt I agree with others that this assert() is pretty useless and should simply be removed.
Re: [PATCH 1/1] net: hns: avoid null pointer dereference
From: Heinrich Schuchardt Date: Tue, 17 May 2016 22:01:15 +0200 > In the statement > assert(priv || priv->ae_handle); > the right side of || is only evaluated if priv is null. > > Signed-off-by: Heinrich Schuchardt I agree with others that this assert() is pretty useless and should simply be removed.
RE: [PATCH 1/1] net: hns: avoid null pointer dereference
From: Heinrich Schuchardt > Sent: 17 May 2016 21:01 > In the statement > assert(priv || priv->ae_handle); > the right side of || is only evaluated if priv is null. > > Signed-off-by: Heinrich Schuchardt> --- > drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 8 > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > index 3d746c8..834a50a 100644 > --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > @@ -720,7 +720,7 @@ static int hns_set_pauseparam(struct net_device *net_dev, > struct hnae_handle *h; > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > h = priv->ae_handle; > ops = h->dev->ops; ... Personally I'd just delete the assert(). It is probably easier to debug the 'oops' from the NULL pointer dereference that that of the assert(). If either value can be NULL (without a coding error) then you'd want to return an error. David
RE: [PATCH 1/1] net: hns: avoid null pointer dereference
From: Heinrich Schuchardt > Sent: 17 May 2016 21:01 > In the statement > assert(priv || priv->ae_handle); > the right side of || is only evaluated if priv is null. > > Signed-off-by: Heinrich Schuchardt > --- > drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 8 > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > index 3d746c8..834a50a 100644 > --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > @@ -720,7 +720,7 @@ static int hns_set_pauseparam(struct net_device *net_dev, > struct hnae_handle *h; > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > h = priv->ae_handle; > ops = h->dev->ops; ... Personally I'd just delete the assert(). It is probably easier to debug the 'oops' from the NULL pointer dereference that that of the assert(). If either value can be NULL (without a coding error) then you'd want to return an error. David
Re: [PATCH 1/1] net: hns: avoid null pointer dereference
Hi Heinrich, This patch is fine to me. Thanks, Yisen 在 2016/5/18 4:01, Heinrich Schuchardt 写道: > In the statement > assert(priv || priv->ae_handle); > the right side of || is only evaluated if priv is null. > > Signed-off-by: Heinrich Schuchardt> --- > drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 8 > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > index 3d746c8..834a50a 100644 > --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > @@ -720,7 +720,7 @@ static int hns_set_pauseparam(struct net_device *net_dev, > struct hnae_handle *h; > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > h = priv->ae_handle; > ops = h->dev->ops; > @@ -780,7 +780,7 @@ static int hns_set_coalesce(struct net_device *net_dev, > struct hnae_ae_ops *ops; > int ret; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > ops = priv->ae_handle->dev->ops; > > @@ -,7 +,7 @@ void hns_get_regs(struct net_device *net_dev, struct > ethtool_regs *cmd, > struct hns_nic_priv *priv = netdev_priv(net_dev); > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > ops = priv->ae_handle->dev->ops; > > @@ -1135,7 +1135,7 @@ static int hns_get_regs_len(struct net_device *net_dev) > struct hns_nic_priv *priv = netdev_priv(net_dev); > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > ops = priv->ae_handle->dev->ops; > if (!ops->get_regs_len) { >
Re: [PATCH 1/1] net: hns: avoid null pointer dereference
Hi Heinrich, This patch is fine to me. Thanks, Yisen 在 2016/5/18 4:01, Heinrich Schuchardt 写道: > In the statement > assert(priv || priv->ae_handle); > the right side of || is only evaluated if priv is null. > > Signed-off-by: Heinrich Schuchardt > --- > drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 8 > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > index 3d746c8..834a50a 100644 > --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c > @@ -720,7 +720,7 @@ static int hns_set_pauseparam(struct net_device *net_dev, > struct hnae_handle *h; > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > h = priv->ae_handle; > ops = h->dev->ops; > @@ -780,7 +780,7 @@ static int hns_set_coalesce(struct net_device *net_dev, > struct hnae_ae_ops *ops; > int ret; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > ops = priv->ae_handle->dev->ops; > > @@ -,7 +,7 @@ void hns_get_regs(struct net_device *net_dev, struct > ethtool_regs *cmd, > struct hns_nic_priv *priv = netdev_priv(net_dev); > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > ops = priv->ae_handle->dev->ops; > > @@ -1135,7 +1135,7 @@ static int hns_get_regs_len(struct net_device *net_dev) > struct hns_nic_priv *priv = netdev_priv(net_dev); > struct hnae_ae_ops *ops; > > - assert(priv || priv->ae_handle); > + assert(priv && priv->ae_handle); > > ops = priv->ae_handle->dev->ops; > if (!ops->get_regs_len) { >
[PATCH 1/1] net: hns: avoid null pointer dereference
In the statement assert(priv || priv->ae_handle); the right side of || is only evaluated if priv is null. Signed-off-by: Heinrich Schuchardt--- drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c index 3d746c8..834a50a 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c @@ -720,7 +720,7 @@ static int hns_set_pauseparam(struct net_device *net_dev, struct hnae_handle *h; struct hnae_ae_ops *ops; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); h = priv->ae_handle; ops = h->dev->ops; @@ -780,7 +780,7 @@ static int hns_set_coalesce(struct net_device *net_dev, struct hnae_ae_ops *ops; int ret; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); ops = priv->ae_handle->dev->ops; @@ -,7 +,7 @@ void hns_get_regs(struct net_device *net_dev, struct ethtool_regs *cmd, struct hns_nic_priv *priv = netdev_priv(net_dev); struct hnae_ae_ops *ops; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); ops = priv->ae_handle->dev->ops; @@ -1135,7 +1135,7 @@ static int hns_get_regs_len(struct net_device *net_dev) struct hns_nic_priv *priv = netdev_priv(net_dev); struct hnae_ae_ops *ops; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); ops = priv->ae_handle->dev->ops; if (!ops->get_regs_len) { -- 2.1.4
[PATCH 1/1] net: hns: avoid null pointer dereference
In the statement assert(priv || priv->ae_handle); the right side of || is only evaluated if priv is null. Signed-off-by: Heinrich Schuchardt --- drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c index 3d746c8..834a50a 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c @@ -720,7 +720,7 @@ static int hns_set_pauseparam(struct net_device *net_dev, struct hnae_handle *h; struct hnae_ae_ops *ops; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); h = priv->ae_handle; ops = h->dev->ops; @@ -780,7 +780,7 @@ static int hns_set_coalesce(struct net_device *net_dev, struct hnae_ae_ops *ops; int ret; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); ops = priv->ae_handle->dev->ops; @@ -,7 +,7 @@ void hns_get_regs(struct net_device *net_dev, struct ethtool_regs *cmd, struct hns_nic_priv *priv = netdev_priv(net_dev); struct hnae_ae_ops *ops; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); ops = priv->ae_handle->dev->ops; @@ -1135,7 +1135,7 @@ static int hns_get_regs_len(struct net_device *net_dev) struct hns_nic_priv *priv = netdev_priv(net_dev); struct hnae_ae_ops *ops; - assert(priv || priv->ae_handle); + assert(priv && priv->ae_handle); ops = priv->ae_handle->dev->ops; if (!ops->get_regs_len) { -- 2.1.4