Module Name: src Committed By: msaitoh Date: Tue Oct 1 18:44:24 UTC 2019
Modified Files: src/sys/external/bsd/drm2/dist/drm/i915: i915_gem_stolen.c Log Message: Avoid undefined behavior in g4x_get_stolen_reserved(). The change is the same as newer i915_gem_stolen.c. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 \ src/sys/external/bsd/drm2/dist/drm/i915/i915_gem_stolen.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/drm2/dist/drm/i915/i915_gem_stolen.c diff -u src/sys/external/bsd/drm2/dist/drm/i915/i915_gem_stolen.c:1.11 src/sys/external/bsd/drm2/dist/drm/i915/i915_gem_stolen.c:1.12 --- src/sys/external/bsd/drm2/dist/drm/i915/i915_gem_stolen.c:1.11 Thu Sep 13 08:25:55 2018 +++ src/sys/external/bsd/drm2/dist/drm/i915/i915_gem_stolen.c Tue Oct 1 18:44:24 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: i915_gem_stolen.c,v 1.11 2018/09/13 08:25:55 mrg Exp $ */ +/* $NetBSD: i915_gem_stolen.c,v 1.12 2019/10/01 18:44:24 msaitoh Exp $ */ /* * Copyright © 2008-2012 Intel Corporation @@ -29,7 +29,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: i915_gem_stolen.c,v 1.11 2018/09/13 08:25:55 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: i915_gem_stolen.c,v 1.12 2019/10/01 18:44:24 msaitoh Exp $"); #include <linux/printk.h> #include <linux/err.h> @@ -308,18 +308,13 @@ static void g4x_get_stolen_reserved(stru unsigned long stolen_top = dev_priv->mm.stolen_base + dev_priv->gtt.stolen_size; - *base = (reg_val & G4X_STOLEN_RESERVED_ADDR2_MASK) << 16; + if (!(reg_val & G4X_STOLEN_RESERVED_ADDR2_MASK)) + return; + *base = (reg_val & G4X_STOLEN_RESERVED_ADDR2_MASK) << 16; WARN_ON((reg_val & G4X_STOLEN_RESERVED_ADDR1_MASK) < *base); - /* On these platforms, the register doesn't have a size field, so the - * size is the distance between the base and the top of the stolen - * memory. We also have the genuine case where base is zero and there's - * nothing reserved. */ - if (*base == 0) - *size = 0; - else - *size = stolen_top - *base; + *size = stolen_top - *base; } static void gen6_get_stolen_reserved(struct drm_i915_private *dev_priv,