Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752011AbdGGJdI (ORCPT ); Fri, 7 Jul 2017 05:33:08 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:34173 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751828AbdGGJdG (ORCPT ); Fri, 7 Jul 2017 05:33:06 -0400 Date: Fri, 7 Jul 2017 11:33:00 +0200 From: Thierry Reding To: Chen-Yu Tsai Cc: "Gustavo A. R. Silva" , Maxime Ripard , linux-pwm@vger.kernel.org, linux-kernel , linux-arm-kernel Subject: Re: [PATCH] pwm: sun4i: add NULL check on of_match_device() return value Message-ID: <20170707093300.GD15652@ulmo.fritz.box> References: <20170707063939.GA20510@embeddedgus> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UfEAyuTBtIjiZzX6" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2399 Lines: 62 --UfEAyuTBtIjiZzX6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 07, 2017 at 03:16:23PM +0800, Chen-Yu Tsai wrote: > On Fri, Jul 7, 2017 at 2:39 PM, Gustavo A. R. Silva > wrote: > > Check return value from call to of_match_device() > > in order to prevent a NULL pointer dereference. > > > > In case of NULL print error message and return -ENODEV > > > > Signed-off-by: Gustavo A. R. Silva > > --- > > drivers/pwm/pwm-sun4i.c | 4 ++++ > > 1 file changed, 4 insertions(+) > > > > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c > > index 1284ffa..295ca19 100644 > > --- a/drivers/pwm/pwm-sun4i.c > > +++ b/drivers/pwm/pwm-sun4i.c > > @@ -321,6 +321,10 @@ static int sun4i_pwm_probe(struct platform_device = *pdev) > > const struct of_device_id *match; > > > > match =3D of_match_device(sun4i_pwm_dt_ids, &pdev->dev); >=20 > AFAIK this simply can not and should not fail with a device tree > only driver with properly populated of_device_id tables. Technically this could happen if someone manually created the platform device. In that case the core will try to match by name if there is no device node to use for a match against the list of of_device_ids. In my opinion it's best to let things crash in this situation to make it really obvious that people have done something wrong. Thierry --UfEAyuTBtIjiZzX6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAllfVUwACgkQ3SOs138+ s6Gc6g/+LdvqJUo+ajApii8vD2L+2EtlY7HJbHYmnwZORSdXeAwJnGpl2yUKqVI4 LmNOgGPbu4c4iUeMqMo9ZRfbAthgHQUi3Z4bD53IWnhJC+cv+OslE3eysGK96Jks ygoHCc73usGKPr4A2KI/B8fAuPOZ4NhZoOsfD9ifEPh1vAV1GIn+62nGYUzXZAii l3oxMAcqEn8MBMoWlFWb/bEEDldXnQc20Str27xIvbVpkjjzch2fBrpFoA/6MYGp CRfMa7kRX8lF109JH95pTeGV20YwozXfXr5iLZR7Q0XcYcjTVxvmx0ESFiwdlU1U NElKj3vw/TwR+8mVytNK8yVW8EwEXuss2ij2RUoRDo4V809jaqoQT4gR/49bY+Tn i2RBqT7uAhb6FHgZmphIfaC3u0ACVR8Pegx5ggdXZZyQDTaV01WI/1m9YDySxfOs qmT2vD2RWJYvcn1MVohj7uZEnPkIe9rZACznPB56N7RQDa6gos/HtcIcHL2Nwxvi FP12SMZ1qszKBbNDH/As53nKiFnzdj5k+nfjv4aRfm7ASOcpJfG/oneJyHSs9Sle DRkNsXDa70AKGRT80Q7aVgAV6cM86LNQ2sisZXDq694pe0T8l1Oo5UXghKddwwTx t/tubn+v+uLBAKCax4jrKhEs3Zy+9HW885RYQxckW/9/6HIzDzc= =4AuE -----END PGP SIGNATURE----- --UfEAyuTBtIjiZzX6--