public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-media@vger.kernel.org
Subject: Re: [media] media-entity: protect object creation/removal using spin lock
Date: Mon, 14 Dec 2015 18:00:52 -0200	[thread overview]
Message-ID: <20151214180052.4262a0a8@recife.lan> (raw)
In-Reply-To: <20151214195053.GA15098@mwanda>

Em Mon, 14 Dec 2015 22:50:53 +0300
Dan Carpenter <dan.carpenter@oracle.com> escreveu:

> Hello Mauro Carvalho Chehab,
> 
> The patch f8fd4c61b5ae: "[media] media-entity: protect object
> creation/removal using spin lock" from Dec 9, 2015, leads to the
> following static checker warning:
> 
> 	drivers/media/media-entity.c:781 media_remove_intf_link()
> 	error: dereferencing freed memory 'link'
> 
> drivers/media/media-entity.c
>    777  void media_remove_intf_link(struct media_link *link)
>    778  {
>    779          spin_lock(&link->graph_obj.mdev->lock);
>    780          __media_remove_intf_link(link);
>    781          spin_unlock(&link->graph_obj.mdev->lock);

Thanks for pointing it!

> 
> Do we need this unlock any more? 

Yes.

> Haven't we freed the lock on the previous line?

No. The lock is at the media_device struct, with is not freed here.

What we actually need is to cache mdev:

	struct media_device *mdev = link->graph_obj.mdev;

	spin_lock(&mdev->lock)
	__media_remove_intf_link(link);
	spin_unlock(&mdev->lock)


Probably the same thing is needed on other similar logic.

I guess gcc optimizer actually does the right thing, but we should
fix it to remove the static analyzer warnings.

Regards,
Mauro

> 
>    782  }
> 
> regards,
> dan carpenter

  reply	other threads:[~2015-12-14 20:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-14 19:50 [media] media-entity: protect object creation/removal using spin lock Dan Carpenter
2015-12-14 20:00 ` Mauro Carvalho Chehab [this message]
2015-12-14 20:04   ` Dan Carpenter
2015-12-14 22:38     ` Mauro Carvalho Chehab

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=20151214180052.4262a0a8@recife.lan \
    --to=mchehab@osg.samsung.com \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-media@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox