All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [bug report] ppdev: fix memory leak
Date: Thu, 15 Dec 2016 21:08:43 +0000	[thread overview]
Message-ID: <20161215210843.GA28981@elgon.mountain> (raw)

Hello Sudip Mukherjee,

The patch 2bd362d5f45c: "ppdev: fix memory leak" from Nov 10, 2016,
leads to the following static checker warning:

	drivers/char/ppdev.c:314 register_device()
	warn: passing freed memory 'name'

drivers/char/ppdev.c
   287  static int register_device(int minor, struct pp_struct *pp)
   288  {
   289          struct parport *port;
   290          struct pardevice *pdev = NULL;
   291          char *name;
   292          struct pardev_cb ppdev_cb;
   293  
   294          name = kasprintf(GFP_KERNEL, CHRDEV "%x", minor);
   295          if (name = NULL)
   296                  return -ENOMEM;
   297  
   298          port = parport_find_number(minor);
   299          if (!port) {
   300                  pr_warn("%s: no associated port!\n", name);
   301                  kfree(name);
   302                  return -ENXIO;
   303          }
   304  
   305          memset(&ppdev_cb, 0, sizeof(ppdev_cb));
   306          ppdev_cb.irq_func = pp_irq;
   307          ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0;
   308          ppdev_cb.private = pp;
   309          pdev = parport_register_dev_model(port, name, &ppdev_cb, minor);
   310          parport_put_port(port);
   311          kfree(name);
                      ^^^^
Free.

   312  
   313          if (!pdev) {
   314                  pr_warn("%s: failed to register device!\n", name);
                                                                    ^^^^
Use after free.

   315                  return -ENXIO;
   316          }
   317  
   318          pp->pdev = pdev;
   319          dev_dbg(&pdev->dev, "registered pardevice\n");
   320          return 0;
   321  }

regards,
dan carpenter

             reply	other threads:[~2016-12-15 21:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-15 21:08 Dan Carpenter [this message]
2016-12-15 21:13 ` [bug report] ppdev: fix memory leak Sudip Mukherjee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161215210843.GA28981@elgon.mountain \
    --to=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.