Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3835561pxy; Mon, 26 Apr 2021 10:52:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhvcP+6O9/1T/rS2d3+2OsP5x4RzgNv58mdXVcTclDYa8cYAh0dawJS6LeyonKLI4AmK8K X-Received: by 2002:a17:906:6bc8:: with SMTP id t8mr20185361ejs.115.1619459522821; Mon, 26 Apr 2021 10:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619459522; cv=none; d=google.com; s=arc-20160816; b=VSMDtEqBbd2XZXp6lZIgcDcO9rVXIHIT7jHBWKRqIKiYSRgE/JkR84HtcneCp8ZZGH BtXmY3GUc9uh+t72IeSGpdWvZni1bq/P91oaAZtu0KjwMpdCHZ9N28qnZhEWOo85YgdC wzqjK65gUukh+ujAArkbWmRo/yxPX0ZFZJbpIW102wLDW5qoZh2csGx6KyDhVli6i9Q5 q80D/s+kN57q5xVg/w3eMRkoA1dQ8U2uSCD94yhGFO12rFdl5/pAVw9Q9HdIJgmj1ez0 fZOQ0UmBIe+ChvizAcXNGmH73y3iAlawbdbrwehm3UkYT1NwGMr5oflr9PoYh/AR/5kl dfFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=h9LWCOWHC0GMijbiMtiImgD8ClqnZSAqZ11QuJHpVYk=; b=M1DBBWyc6YEFYktgmHWkW87HXT+2hcYWdDRnRsUWDIb+H2mogo4uPO4M7NVaGQxjGX qlZ3w6rnht3fzSLZvrEwgpQlUDmjVvro3yEef9Q1zX577l8QmGpy1ohhXdwyXELCZKqG p5yx1xMR7gq6a9lduaBeKjXLC/dr4pnxSCVmKOx7p1DIcse6OqfVY/cSl2FlUT6jpbMS k0IDUWL02XhNK+EGktXDG35tgR/+S4xCEVvJBzKmoYiVBLAicYToJoGnwCwQe372+loe uiY/2wGiXmlbR+R4QkMna6SjdT3r9BJ8r2OrRe5hsBjBlNr83veQn6P8iF+RnVPpWGda uh0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pesu-pes-edu.20150623.gappssmtp.com header.s=20150623 header.b="x+SV7A/F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=pes.edu Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j17si386480eds.555.2021.04.26.10.51.38; Mon, 26 Apr 2021 10:52:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pesu-pes-edu.20150623.gappssmtp.com header.s=20150623 header.b="x+SV7A/F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=pes.edu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237505AbhDZRvW (ORCPT + 99 others); Mon, 26 Apr 2021 13:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237467AbhDZRvU (ORCPT ); Mon, 26 Apr 2021 13:51:20 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF862C061756 for ; Mon, 26 Apr 2021 10:50:38 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id s14so22585932pjl.5 for ; Mon, 26 Apr 2021 10:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pesu-pes-edu.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=h9LWCOWHC0GMijbiMtiImgD8ClqnZSAqZ11QuJHpVYk=; b=x+SV7A/FAHaPR7u2hfg9wJuW/1PCQpCTHkIC7ZUGfn3XDVyYZIS+7nUQ0jSbszDFF8 SYvTrRxtrGSYG9B6JEnCyn55lNzNFAnqp30/PhB/6kclCbRbntHDAAunE6nbgSuEVQUD 7TtW1nvu9l1X0uhwaouiN6PpBEANjB+EZV1cEGG/z0dyhmtzWsFKoRvv5cMx6DAPJpLE 3qA4uPl3hBxrdntdK+gjkcIT4APhYI9RVLuNc55yfLlkIgbEBMqMjXNryBZQaJSWBShR jfiXGK4x5GD7DuOD0eVel9kxjNUSzd8l6rwND7yC35tJm2fgftzzDVIHENqstdOU0reN E89g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=h9LWCOWHC0GMijbiMtiImgD8ClqnZSAqZ11QuJHpVYk=; b=XPiJCTZ84RhWG/xD3Up+L064SyCc84V2CCiDnhGJZ33WB4QYfsXdzhhlaaaAc4jdwR XfQ1tXvZfb1OWI36do2OIJUAOJqG/c+6rWh9X3r+8Tow5Bl3gHDf50WE689c+RpA09dM f86VRGRb1HXtR5G5Z0JcZEEKwmIpdoM5EXlWKdXFTDxVfb3bi2ywTgB72tOw2d/A+nPi irbl8B6TeEXh4ylVssJoEEd2jzpjOLLtSAOb0ma84TqW2xORHdyiylZ9euEGmdb+Kq6c AykKKYh03TuAB5enmzNR4J8xnz4AUdw8wKpv1jy2KOPyWoQu69BcjznXrHu1Yi8ozLj8 /QMw== X-Gm-Message-State: AOAM530tKaN5VsUYzub3+S/bgjz53PnbpeDXVlFpjn0xVbM9hunko6ZE UjAGsimC68SEZxQb0hKyOFE8s2OphegKRg== X-Received: by 2002:a17:90a:e643:: with SMTP id ep3mr263249pjb.194.1619459438062; Mon, 26 Apr 2021 10:50:38 -0700 (PDT) Received: from localhost ([2406:7400:73:bf98:cdf4:fbe8:4446:3272]) by smtp.gmail.com with ESMTPSA id r3sm306586pfl.159.2021.04.26.10.50.36 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Apr 2021 10:50:37 -0700 (PDT) Date: Mon, 26 Apr 2021 23:20:32 +0530 From: bkkarthik To: Leon Romanovsky Cc: Anupama K Patil , Jaroslav Kysela , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, kernelnewbies@kernelnewbies.org Subject: Re: [PATCH] drivers: pnp: proc.c: Handle errors while attaching devices Message-ID: <20210426175031.w26ovnffjiow346h@burgerking> References: <20210424194301.jmsqpycvsm7izbk3@ubuntu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="lavq234wszdgqeqb" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20171215 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --lavq234wszdgqeqb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 21/04/26 08:04AM, Leon Romanovsky wrote: > On Sun, Apr 25, 2021 at 01:13:01AM +0530, Anupama K Patil wrote: > > isapnp_proc_init() does not look at the return value from > > isapnp_proc_attach_device(). Check for this return value in > > isapnp_proc_detach_device(). > >=20 > > Cleanup in isapnp_proc_detach_device and > > isapnp_proc_detach_bus() for cleanup. > >=20 > > Changed sprintf() to the kernel-space function scnprintf() as it returns > > the actual number of bytes written. > >=20 > > Removed unnecessary variables de, e of type 'struct proc_dir_entry' to > > save memory. >=20 > What exactly do you fix for such an old code? I was not aware that this code is so old. This fix was made after checkpatc= h reported assignment inside an if-statement. Please ignore this patch if th change is not necessary as the code is proba= bly not being used anywhere :) Maybe the code has to be marked as obsolete in the MAINTAINERS file to prev= ent patches being sent? >=20 > >=20 > > Suggested-by: Shuah Khan > > Co-developed-by: B K Karthik > > Signed-off-by: B K Karthik > > Signed-off-by: Anupama K Patil > > --- > > drivers/pnp/isapnp/proc.c | 40 +++++++++++++++++++++++++++++---------- > > 1 file changed, 30 insertions(+), 10 deletions(-) > >=20 > > diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c > > index 785a796430fa..46ebc24175b7 100644 > > --- a/drivers/pnp/isapnp/proc.c > > +++ b/drivers/pnp/isapnp/proc.c > > @@ -54,34 +54,54 @@ static const struct proc_ops isapnp_proc_bus_proc_o= ps =3D { > > .proc_read =3D isapnp_proc_bus_read, > > }; > > =20 > > +static int isapnp_proc_detach_device(struct pnp_dev *dev) > > +{ > > + proc_remove(dev->procent); > > + dev->procent =3D NULL; > > + return 0; > > +} > > + > > +static int isapnp_proc_detach_bus(struct pnp_card *bus) > > +{ > > + proc_remove(bus->procdir); > > + return 0; > > +} >=20 > Please don't add one line functions that are called only once and have > return value that no one care about it. These were only intended for a clean-up job, the idea of this function came= from how PCI handles procfs. Maybe those should be changed? thanks, karthik >=20 > Thanks >=20 > > + > > static int isapnp_proc_attach_device(struct pnp_dev *dev) > > { > > struct pnp_card *bus =3D dev->card; > > - struct proc_dir_entry *de, *e; > > char name[16]; > > =20 > > - if (!(de =3D bus->procdir)) { > > - sprintf(name, "%02x", bus->number); > > - de =3D bus->procdir =3D proc_mkdir(name, isapnp_proc_bus_dir); > > - if (!de) > > + if (!bus->procdir) { > > + scnprintf(name, 16, "%02x", bus->number); > > + bus->procdir =3D proc_mkdir(name, isapnp_proc_bus_dir); > > + if (!bus->procdir) > > return -ENOMEM; > > } > > - sprintf(name, "%02x", dev->number); > > - e =3D dev->procent =3D proc_create_data(name, S_IFREG | S_IRUGO, de, > > + scnprintf(name, 16, "%02x", dev->number); > > + dev->procent =3D proc_create_data(name, S_IFREG | S_IRUGO, bus->procd= ir, > > &isapnp_proc_bus_proc_ops, dev); > > - if (!e) > > + if (!dev->procent) { > > + isapnp_proc_detach_bus(bus); > > return -ENOMEM; > > - proc_set_size(e, 256); > > + } > > + proc_set_size(dev->procent, 256); > > return 0; > > } > > =20 > > int __init isapnp_proc_init(void) > > { > > struct pnp_dev *dev; > > + int dev_attach; > > =20 > > isapnp_proc_bus_dir =3D proc_mkdir("bus/isapnp", NULL); > > protocol_for_each_dev(&isapnp_protocol, dev) { > > - isapnp_proc_attach_device(dev); > > + dev_attach =3D isapnp_proc_attach_device(dev); > > + if (!dev_attach) { > > + pr_info("procfs: pnp: Unable to attach the device, not enough memor= y"); > > + isapnp_proc_detach_device(dev); > > + return -ENOMEM; > > + } > > } > > return 0; > > } > > --=20 > > 2.25.1 > >=20 >=20 >=20 >=20 > > _______________________________________________ > > Kernelnewbies mailing list > > Kernelnewbies@kernelnewbies.org > > https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies >=20 --lavq234wszdgqeqb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAEBCgAdFiEEIRwfsurAmIAiSNrGB1QtCt0juC0FAmCG/WcACgkQB1QtCt0j uC11vwwAi4ARtpvImmmTw+EvCLEVfj2smNdk3Gxx11VQqDO/9k0Ab/+gmuQabNQO etGO9SKLY11b2jXhOAklk+O+2aHx7zqcBS+3svTAo591Oy9VYhwE9OsTjG51zQTK x+wS9NtJyLG3YgrAjRhfeNs+eu3iYO5R3NPP2TEkESFND0B/T66oZ/0/++Idu8tj pDtWG7ga1DaQrCrMTSBKYIa4pSFDCS3u0trAzvduBhPWDXaXaeGTwjO/a9Wc5RgL DxkKUQc7RmBOFKr/HjgKOqsbMnDU5c29LZTkka3ZuXq2/2+KXCqHppBdI04ksJad aZDS2oz3Xc4NrbhR9bW/Q0KaYDwJYXt4SEooS34BKNazq3GvHvVcjfF7ItbQKhqk 74+QgEzhwiaj38fF00OHOu/ygrg6n20QJgsEfpiR7Q2XeABakKkSOXp/9QWZkwKq 0/nQubSy7ANQNZpeVW18dwU71eeAV6D3mi7lZTD+FaHJfkOsh0qKfLDs7qTi0MnF 1nX5yucQ =SNr5 -----END PGP SIGNATURE----- --lavq234wszdgqeqb--