From 159fc1d722ce9dd763313e018f34a260d01af9f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Tigeot?= Date: Fri, 6 Feb 2015 16:50:03 +0100 Subject: [PATCH] drm/i915: Use kzalloc() Fix little differences with Linux 3.10 when appropriate. --- sys/dev/drm/i915/i915_dma.c | 5 ++--- sys/dev/drm/i915/i915_gem.c | 5 ++--- sys/dev/drm/i915/i915_gem_context.c | 2 +- sys/dev/drm/i915/i915_gem_execbuffer.c | 4 ++-- sys/dev/drm/i915/i915_gem_gtt.c | 6 ++--- sys/dev/drm/i915/i915_irq.c | 2 +- sys/dev/drm/i915/intel_bios.c | 6 ++--- sys/dev/drm/i915/intel_crt.c | 5 ++--- sys/dev/drm/i915/intel_ddi.c | 10 ++++----- sys/dev/drm/i915/intel_display.c | 14 +++++------- sys/dev/drm/i915/intel_dp.c | 6 ++--- sys/dev/drm/i915/intel_fb.c | 2 +- sys/dev/drm/i915/intel_hdmi.c | 6 ++--- sys/dev/drm/i915/intel_lvds.c | 6 ++--- sys/dev/drm/i915/intel_overlay.c | 6 ++--- sys/dev/drm/i915/intel_pm.c | 2 +- sys/dev/drm/i915/intel_sdvo.c | 31 ++++++++++++++------------ sys/dev/drm/i915/intel_sprite.c | 3 +-- sys/dev/drm/i915/intel_tv.c | 5 ++--- 19 files changed, 55 insertions(+), 71 deletions(-) diff --git a/sys/dev/drm/i915/i915_dma.c b/sys/dev/drm/i915/i915_dma.c index 608707bd78..6a73107a98 100644 --- a/sys/dev/drm/i915/i915_dma.c +++ b/sys/dev/drm/i915/i915_dma.c @@ -1406,8 +1406,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) dev->types[8] = _DRM_STAT_SECONDARY; dev->types[9] = _DRM_STAT_DMA; - dev_priv = kmalloc(sizeof(drm_i915_private_t), M_DRM, - M_ZERO | M_WAITOK); + dev_priv = kzalloc(sizeof(drm_i915_private_t), GFP_KERNEL); if (dev_priv == NULL) return -ENOMEM; @@ -1706,7 +1705,7 @@ int i915_driver_open(struct drm_device *dev, struct drm_file *file) struct drm_i915_file_private *file_priv; DRM_DEBUG_DRIVER("\n"); - file_priv = kmalloc(sizeof(*file_priv), M_DRM, M_WAITOK | M_ZERO); + file_priv = kmalloc(sizeof(*file_priv), M_DRM, M_WAITOK); if (!file_priv) return -ENOMEM; diff --git a/sys/dev/drm/i915/i915_gem.c b/sys/dev/drm/i915/i915_gem.c index f81ace7937..95743d114e 100644 --- a/sys/dev/drm/i915/i915_gem.c +++ b/sys/dev/drm/i915/i915_gem.c @@ -1630,7 +1630,7 @@ i915_add_request(struct intel_ring_buffer *ring, if (ret) return ret; - request = kmalloc(sizeof(*request), M_DRM, M_WAITOK | M_ZERO); + request = kmalloc(sizeof(*request), M_DRM, M_WAITOK); if (request == NULL) return -ENOMEM; @@ -3850,8 +3850,7 @@ static int i915_gem_init_phys_object(struct drm_device *dev, if (dev_priv->mm.phys_objs[id - 1] || !size) return 0; - phys_obj = kmalloc(sizeof(struct drm_i915_gem_phys_object), M_DRM, - M_WAITOK | M_ZERO); + phys_obj = kzalloc(sizeof(struct drm_i915_gem_phys_object), GFP_KERNEL); if (!phys_obj) return -ENOMEM; diff --git a/sys/dev/drm/i915/i915_gem_context.c b/sys/dev/drm/i915/i915_gem_context.c index fed7afd001..46fdf64763 100644 --- a/sys/dev/drm/i915/i915_gem_context.c +++ b/sys/dev/drm/i915/i915_gem_context.c @@ -142,7 +142,7 @@ create_hw_context(struct drm_device *dev, struct i915_hw_context *ctx; int ret, id; - ctx = kmalloc(sizeof(*ctx), M_DRM, M_WAITOK | M_ZERO); + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (ctx == NULL) return ERR_PTR(-ENOMEM); diff --git a/sys/dev/drm/i915/i915_gem_execbuffer.c b/sys/dev/drm/i915/i915_gem_execbuffer.c index 2b4918ef70..a26d94a155 100644 --- a/sys/dev/drm/i915/i915_gem_execbuffer.c +++ b/sys/dev/drm/i915/i915_gem_execbuffer.c @@ -60,9 +60,9 @@ eb_create(struct drm_i915_gem_execbuffer2 *args) BUILD_BUG_ON_NOT_POWER_OF_2(PAGE_SIZE / sizeof(struct hlist_head)); while (count > 2*size) count >>= 1; - eb = kmalloc(count*sizeof(struct hlist_head) + + eb = kzalloc(count*sizeof(struct hlist_head) + sizeof(struct eb_objects), - M_DRM, M_WAITOK | M_ZERO); + GFP_TEMPORARY); if (eb == NULL) return eb; diff --git a/sys/dev/drm/i915/i915_gem_gtt.c b/sys/dev/drm/i915/i915_gem_gtt.c index 41f93e41bd..4c4d56cd1b 100644 --- a/sys/dev/drm/i915/i915_gem_gtt.c +++ b/sys/dev/drm/i915/i915_gem_gtt.c @@ -258,8 +258,8 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) ppgtt->clear_range = gen6_ppgtt_clear_range; ppgtt->insert_entries = gen6_ppgtt_insert_entries; ppgtt->cleanup = gen6_ppgtt_cleanup; - ppgtt->pt_pages = kmalloc(sizeof(vm_page_t) * ppgtt->num_pd_entries, - M_DRM, M_WAITOK | M_ZERO); + ppgtt->pt_pages = kzalloc(sizeof(struct vm_page *)*ppgtt->num_pd_entries, + GFP_KERNEL); if (!ppgtt->pt_pages) return -ENOMEM; @@ -290,7 +290,7 @@ static int i915_gem_init_aliasing_ppgtt(struct drm_device *dev) struct i915_hw_ppgtt *ppgtt; int ret; - ppgtt = kmalloc(sizeof(*ppgtt), M_DRM, M_WAITOK | M_ZERO); + ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); if (!ppgtt) return -ENOMEM; diff --git a/sys/dev/drm/i915/i915_irq.c b/sys/dev/drm/i915/i915_irq.c index e7ca102d28..33bdc17afd 100644 --- a/sys/dev/drm/i915/i915_irq.c +++ b/sys/dev/drm/i915/i915_irq.c @@ -1462,7 +1462,7 @@ static void i915_capture_error_state(struct drm_device *dev) return; /* Account for pipe specific data like PIPE*STAT */ - error = kmalloc(sizeof(*error), M_DRM, M_WAITOK | M_NULLOK | M_ZERO); + error = kzalloc(sizeof(*error), GFP_ATOMIC); if (!error) { DRM_DEBUG_DRIVER("out of memory, not capturing error state\n"); return; diff --git a/sys/dev/drm/i915/intel_bios.c b/sys/dev/drm/i915/intel_bios.c index 8c26912159..2fd657c88b 100644 --- a/sys/dev/drm/i915/intel_bios.c +++ b/sys/dev/drm/i915/intel_bios.c @@ -231,8 +231,7 @@ parse_lfp_panel_data(struct drm_i915_private *dev_priv, lvds_lfp_data_ptrs, lvds_options->panel_type); - panel_fixed_mode = kmalloc(sizeof(*panel_fixed_mode), M_DRM, - M_WAITOK | M_ZERO); + panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL); if (!panel_fixed_mode) return; @@ -310,8 +309,7 @@ parse_sdvo_panel_data(struct drm_i915_private *dev_priv, if (!dvo_timing) return; - panel_fixed_mode = kmalloc(sizeof(*panel_fixed_mode), M_DRM, - M_WAITOK | M_ZERO); + panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL); if (!panel_fixed_mode) return; diff --git a/sys/dev/drm/i915/intel_crt.c b/sys/dev/drm/i915/intel_crt.c index d5be38e522..cbf57e8b8b 100644 --- a/sys/dev/drm/i915/intel_crt.c +++ b/sys/dev/drm/i915/intel_crt.c @@ -731,12 +731,11 @@ void intel_crt_init(struct drm_device *dev) if (dmi_check_system(intel_no_crt)) return; - crt = kmalloc(sizeof(struct intel_crt), M_DRM, M_WAITOK | M_ZERO); + crt = kzalloc(sizeof(struct intel_crt), GFP_KERNEL); if (!crt) return; - intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, - M_WAITOK | M_ZERO); + intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); if (!intel_connector) { kfree(crt); return; diff --git a/sys/dev/drm/i915/intel_ddi.c b/sys/dev/drm/i915/intel_ddi.c index 09ed81770e..2ffc8f3e70 100644 --- a/sys/dev/drm/i915/intel_ddi.c +++ b/sys/dev/drm/i915/intel_ddi.c @@ -1510,21 +1510,19 @@ void intel_ddi_init(struct drm_device *dev, enum port port) struct intel_connector *hdmi_connector = NULL; struct intel_connector *dp_connector = NULL; - intel_dig_port = kmalloc(sizeof(struct intel_digital_port), - M_DRM, M_WAITOK | M_ZERO); + intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL); if (!intel_dig_port) return; - dp_connector = kmalloc(sizeof(struct intel_connector), - M_DRM, M_WAITOK | M_ZERO); + dp_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); if (!dp_connector) { kfree(intel_dig_port); return; } if (port != PORT_A) { - hdmi_connector = kmalloc(sizeof(struct intel_connector), - M_DRM, M_WAITOK | M_ZERO); + hdmi_connector = kzalloc(sizeof(struct intel_connector), + GFP_KERNEL); if (!hdmi_connector) { kfree(dp_connector); kfree(intel_dig_port); diff --git a/sys/dev/drm/i915/intel_display.c b/sys/dev/drm/i915/intel_display.c index 9a4826e7e3..bf641bad99 100644 --- a/sys/dev/drm/i915/intel_display.c +++ b/sys/dev/drm/i915/intel_display.c @@ -6565,7 +6565,7 @@ intel_framebuffer_create(struct drm_device *dev, struct intel_framebuffer *intel_fb; int ret; - intel_fb = kmalloc(sizeof(*intel_fb), M_DRM, M_WAITOK | M_ZERO); + intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); if (!intel_fb) { drm_gem_object_unreference_unlocked(&obj->base); return ERR_PTR(-ENOMEM); @@ -6884,7 +6884,7 @@ struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, int vtot = I915_READ(VTOTAL(cpu_transcoder)); int vsync = I915_READ(VSYNC(cpu_transcoder)); - mode = kmalloc(sizeof(*mode), M_DRM, M_WAITOK | M_ZERO); + mode = kzalloc(sizeof(*mode), GFP_KERNEL); if (!mode) return NULL; @@ -7393,7 +7393,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, fb->pitches[0] != crtc->fb->pitches[0])) return -EINVAL; - work = kmalloc(sizeof *work, M_DRM, M_WAITOK | M_ZERO); + work = kzalloc(sizeof *work, GFP_KERNEL); if (work == NULL) return -ENOMEM; @@ -7643,7 +7643,7 @@ intel_modeset_pipe_config(struct drm_crtc *crtc, struct intel_crtc_config *pipe_config; int plane_bpp; - pipe_config = kmalloc(sizeof(*pipe_config), M_DRM, M_WAITOK | M_ZERO); + pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); if (!pipe_config) return ERR_PTR(-ENOMEM); @@ -8360,7 +8360,7 @@ static int intel_crtc_set_config(struct drm_mode_set *set) dev = set->crtc->dev; ret = -ENOMEM; - config = kmalloc(sizeof(*config), M_DRM, M_WAITOK | M_ZERO); + config = kzalloc(sizeof(*config), GFP_KERNEL); if (!config) goto out_config; @@ -8456,9 +8456,7 @@ static void intel_crtc_init(struct drm_device *dev, int pipe) struct intel_crtc *intel_crtc; int i; - intel_crtc = kmalloc(sizeof(struct intel_crtc) + - (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), - M_DRM, M_WAITOK | M_ZERO); + intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); if (intel_crtc == NULL) return; diff --git a/sys/dev/drm/i915/intel_dp.c b/sys/dev/drm/i915/intel_dp.c index 70efc0bb55..ed445f600f 100644 --- a/sys/dev/drm/i915/intel_dp.c +++ b/sys/dev/drm/i915/intel_dp.c @@ -2966,13 +2966,11 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port) struct drm_encoder *encoder; struct intel_connector *intel_connector; - intel_dig_port = kmalloc(sizeof(struct intel_digital_port), M_DRM, - M_WAITOK | M_ZERO); + intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL); if (!intel_dig_port) return; - intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, - M_WAITOK | M_ZERO); + intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); if (!intel_connector) { kfree(intel_dig_port); return; diff --git a/sys/dev/drm/i915/intel_fb.c b/sys/dev/drm/i915/intel_fb.c index bc1380b9c3..03b545817f 100644 --- a/sys/dev/drm/i915/intel_fb.c +++ b/sys/dev/drm/i915/intel_fb.c @@ -227,7 +227,7 @@ int intel_fbdev_init(struct drm_device *dev) drm_i915_private_t *dev_priv = dev->dev_private; int ret; - ifbdev = kmalloc(sizeof(struct intel_fbdev), M_DRM, M_WAITOK | M_ZERO); + ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL); if (!ifbdev) return -ENOMEM; diff --git a/sys/dev/drm/i915/intel_hdmi.c b/sys/dev/drm/i915/intel_hdmi.c index 4df56c3757..8cc9549518 100644 --- a/sys/dev/drm/i915/intel_hdmi.c +++ b/sys/dev/drm/i915/intel_hdmi.c @@ -1080,13 +1080,11 @@ void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port) struct drm_encoder *encoder; struct intel_connector *intel_connector; - intel_dig_port = kmalloc(sizeof(struct intel_digital_port), M_DRM, - M_WAITOK | M_ZERO); + intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL); if (!intel_dig_port) return; - intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, - M_WAITOK | M_ZERO); + intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); if (!intel_connector) { kfree(intel_dig_port); return; diff --git a/sys/dev/drm/i915/intel_lvds.c b/sys/dev/drm/i915/intel_lvds.c index 51f5b01a70..ba37f96e8b 100644 --- a/sys/dev/drm/i915/intel_lvds.c +++ b/sys/dev/drm/i915/intel_lvds.c @@ -1099,13 +1099,11 @@ bool intel_lvds_init(struct drm_device *dev) } } - lvds_encoder = kmalloc(sizeof(struct intel_lvds_encoder), M_DRM, - M_WAITOK | M_ZERO); + lvds_encoder = kzalloc(sizeof(struct intel_lvds_encoder), GFP_KERNEL); if (!lvds_encoder) return false; - lvds_connector = kmalloc(sizeof(struct intel_lvds_connector), M_DRM, - M_WAITOK | M_ZERO); + lvds_connector = kzalloc(sizeof(struct intel_lvds_connector), GFP_KERNEL); if (!lvds_connector) { kfree(lvds_encoder); return false; diff --git a/sys/dev/drm/i915/intel_overlay.c b/sys/dev/drm/i915/intel_overlay.c index cc1f3cb20c..f20588a305 100644 --- a/sys/dev/drm/i915/intel_overlay.c +++ b/sys/dev/drm/i915/intel_overlay.c @@ -1056,8 +1056,7 @@ int intel_overlay_put_image(struct drm_device *dev, void *data, return ret; } - params = kmalloc(sizeof(struct put_image_params), M_DRM, - M_WAITOK | M_ZERO); + params = kmalloc(sizeof(struct put_image_params), M_DRM, M_WAITOK); if (!params) return -ENOMEM; @@ -1324,8 +1323,7 @@ void intel_setup_overlay(struct drm_device *dev) if (!HAS_OVERLAY(dev)) return; - overlay = kmalloc(sizeof(struct intel_overlay), M_DRM, - M_WAITOK | M_ZERO); + overlay = kzalloc(sizeof(struct intel_overlay), GFP_KERNEL); if (!overlay) return; diff --git a/sys/dev/drm/i915/intel_pm.c b/sys/dev/drm/i915/intel_pm.c index ed940dae5e..9628908082 100644 --- a/sys/dev/drm/i915/intel_pm.c +++ b/sys/dev/drm/i915/intel_pm.c @@ -325,7 +325,7 @@ void intel_enable_fbc(struct drm_crtc *crtc, unsigned long interval) intel_cancel_fbc_work(dev_priv); - work = kmalloc(sizeof(*work), M_DRM, M_WAITOK | M_ZERO); + work = kzalloc(sizeof *work, GFP_KERNEL); if (work == NULL) { dev_priv->display.enable_fbc(crtc, interval); return; diff --git a/sys/dev/drm/i915/intel_sdvo.c b/sys/dev/drm/i915/intel_sdvo.c index 85598e3cc1..c059b82f7b 100644 --- a/sys/dev/drm/i915/intel_sdvo.c +++ b/sys/dev/drm/i915/intel_sdvo.c @@ -447,9 +447,14 @@ static const char *cmd_status_names[] = { static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, const void *args, int args_len) { - u8 buf[args_len*2 + 2], status; + u8 *buf, status; struct iic_msg msgs[args_len + 3]; - int i, ret; + int i, ret = true; + + /* Would be simpler to allocate both in one go ? */ + buf = kzalloc(args_len * 2 + 2, GFP_KERNEL); + if (!buf) + return false; intel_sdvo_debug_write(intel_sdvo, cmd, args, args_len); @@ -483,7 +488,8 @@ static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, ret = iicbus_transfer(intel_sdvo->i2c, msgs, i+3); if (ret != 0) { DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); - return (false); + ret = false; + goto out; } #if 0 if (ret != i+3) { @@ -493,7 +499,9 @@ static bool intel_sdvo_write_cmd(struct intel_sdvo *intel_sdvo, u8 cmd, } #endif - return true; +out: + kfree(buf); + return ret; } static bool intel_sdvo_read_response(struct intel_sdvo *intel_sdvo, @@ -2264,8 +2272,7 @@ intel_sdvo_dvi_init(struct intel_sdvo *intel_sdvo, int device) struct intel_connector *intel_connector; struct intel_sdvo_connector *intel_sdvo_connector; - intel_sdvo_connector = kmalloc(sizeof(struct intel_sdvo_connector), - M_DRM, M_WAITOK | M_ZERO); + intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); if (!intel_sdvo_connector) return false; @@ -2313,8 +2320,7 @@ intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type) struct intel_connector *intel_connector; struct intel_sdvo_connector *intel_sdvo_connector; - intel_sdvo_connector = kmalloc(sizeof(struct intel_sdvo_connector), - M_DRM, M_WAITOK | M_ZERO); + intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); if (!intel_sdvo_connector) return false; @@ -2352,8 +2358,7 @@ intel_sdvo_analog_init(struct intel_sdvo *intel_sdvo, int device) struct intel_connector *intel_connector; struct intel_sdvo_connector *intel_sdvo_connector; - intel_sdvo_connector = kmalloc(sizeof(struct intel_sdvo_connector), - M_DRM, M_WAITOK | M_ZERO); + intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); if (!intel_sdvo_connector) return false; @@ -2384,8 +2389,7 @@ intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device) struct intel_connector *intel_connector; struct intel_sdvo_connector *intel_sdvo_connector; - intel_sdvo_connector = kmalloc(sizeof(struct intel_sdvo_connector), - M_DRM, M_WAITOK | M_ZERO); + intel_sdvo_connector = kzalloc(sizeof(struct intel_sdvo_connector), GFP_KERNEL); if (!intel_sdvo_connector) return false; @@ -2831,8 +2835,7 @@ bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob) u32 hotplug_mask; int i; - intel_sdvo = kmalloc(sizeof(struct intel_sdvo), M_DRM, - M_WAITOK | M_ZERO); + intel_sdvo = kzalloc(sizeof(struct intel_sdvo), GFP_KERNEL); if (!intel_sdvo) return false; diff --git a/sys/dev/drm/i915/intel_sprite.c b/sys/dev/drm/i915/intel_sprite.c index 9e4601ce4a..f5a10fb13b 100644 --- a/sys/dev/drm/i915/intel_sprite.c +++ b/sys/dev/drm/i915/intel_sprite.c @@ -894,8 +894,7 @@ intel_plane_init(struct drm_device *dev, enum i915_pipe pipe, int plane) if (INTEL_INFO(dev)->gen < 5) return -ENODEV; - intel_plane = kmalloc(sizeof(struct intel_plane), M_DRM, - M_WAITOK | M_ZERO); + intel_plane = kzalloc(sizeof(struct intel_plane), GFP_KERNEL); if (!intel_plane) return -ENOMEM; diff --git a/sys/dev/drm/i915/intel_tv.c b/sys/dev/drm/i915/intel_tv.c index 6daeee0463..d68a3313c4 100644 --- a/sys/dev/drm/i915/intel_tv.c +++ b/sys/dev/drm/i915/intel_tv.c @@ -1591,13 +1591,12 @@ intel_tv_init(struct drm_device *dev) (tv_dac_off & TVDAC_STATE_CHG_EN) != 0) return; - intel_tv = kmalloc(sizeof(struct intel_tv), M_DRM, M_WAITOK | M_ZERO); + intel_tv = kzalloc(sizeof(struct intel_tv), GFP_KERNEL); if (!intel_tv) { return; } - intel_connector = kmalloc(sizeof(struct intel_connector), M_DRM, - M_WAITOK | M_ZERO); + intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); if (!intel_connector) { kfree(intel_tv); return; -- 2.41.0