From: akpm@linux-foundation.org Subject: [patch 3/6] gpu: drm/i915, fix potential null dereference Date: Tue, 02 Feb 2010 14:40:31 -0800 Message-ID: <201002022240.o12MeVk8018889@imap1.linux-foundation.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.sourceforge.net To: airlied@linux.ie Cc: akpm@linux-foundation.org, dri-devel@lists.sourceforge.net, jslaby@suse.cz, jbarnes@virtuousgeek.org List-Id: dri-devel@lists.freedesktop.org From: Jiri Slaby Stanse found a potential null dereference in i915_suspend. There is a check for dev and dev_priv being NULL, but dev is dereferenced earlier. Move the dereference after the check. Signed-off-by: Jiri Slaby Cc: David Airlie Cc: Eric Anholt Cc: Jesse Barnes Signed-off-by: Andrew Morton --- drivers/gpu/drm/i915/i915_drv.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff -puN drivers/gpu/drm/i915/i915_drv.c~gpu-drm-i915-fix-potential-null-dereference drivers/gpu/drm/i915/i915_drv.c --- a/drivers/gpu/drm/i915/i915_drv.c~gpu-drm-i915-fix-potential-null-dereference +++ a/drivers/gpu/drm/i915/i915_drv.c @@ -176,12 +176,17 @@ MODULE_DEVICE_TABLE(pci, pciidlist); static int i915_suspend(struct drm_device *dev, pm_message_t state) { - struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_i915_private *dev_priv; - if (!dev || !dev_priv) { - DRM_ERROR("dev: %p, dev_priv: %p\n", dev, dev_priv); - DRM_ERROR("DRM not initialized, aborting suspend.\n"); - return -ENODEV; + if (!dev) { + DRM_ERROR("dev: %p\n", dev); + goto abort; + } + + dev_priv = dev->dev_private; + if (!dev_priv) { + DRM_ERROR("dev_priv: %p\n", dev_priv); + goto abort; } if (state.event == PM_EVENT_PRETHAW) @@ -211,6 +216,9 @@ static int i915_suspend(struct drm_devic dev_priv->modeset_on_lid = 0; return 0; +abort: + DRM_ERROR("DRM not initialized, aborting suspend.\n"); + return -ENODEV; } static int i915_resume(struct drm_device *dev) _ ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com --