/* * MEN 14F021P00 Board Management Controller (BMC) Watchdog Driver. * * Copyright (C) 2014 MEN Mikro Elektronik Nuernberg GmbH * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. */ #include #include #include #include #include #include #define DEVNAME "menf21bmc_wdt" #define BMC_CMD_WD_ON 0x11 #define BMC_CMD_WD_OFF 0x12 #define BMC_CMD_WD_TRIG 0x13 #define BMC_CMD_WD_TIME 0x14 #define BMC_CMD_WD_STATE 0x17 #define BMC_WD_OFF_VAL 0x69 #define BMC_CMD_RST_RSN 0x92 #define BMC_WD_TIMEOUT_MIN 1 /* in sec */ #define BMC_WD_TIMEOUT_MAX 6553 /* in sec */ static bool nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); struct menf21bmc_wdt { struct watchdog_device wdt; struct i2c_client *i2c_client; }; static int menf21bmc_wdt_set_bootstatus(struct menf21bmc_wdt *data) { int rst_rsn; rst_rsn = i2c_smbus_read_byte_data(data->i2c_client, BMC_CMD_RST_RSN); if (rst_rsn < 0) return rst_rsn; if (rst_rsn == 0x02) data->wdt.bootstatus |= WDIOF_CARDRESET; else if (rst_rsn == 0x05) data->wdt.bootstatus |= WDIOF_EXTERN1; else if (rst_rsn == 0x06) data->wdt.bootstatus |= WDIOF_EXTERN2; else if (rst_rsn == 0x0A) data->wdt.bootstatus |= WDIOF_POWERUNDER; return 0; } static int menf21bmc_wdt_start(struct watchdog_device *wdt) { struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt); return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_ON); } static int menf21bmc_wdt_stop(struct watchdog_device *wdt) { struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt); return i2c_smbus_write_byte_data(drv_data->i2c_client, BMC_CMD_WD_OFF, BMC_WD_OFF_VAL); } static int menf21bmc_wdt_settimeout(struct watchdog_device *wdt, unsigned int timeout) { int ret; struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt); /* * BMC Watchdog does have a resolution of 100ms. * Watchdog API defines the timeout in seconds, so we have to * multiply the value. */ ret = i2c_smbus_write_word_data(drv_data->i2c_client, BMC_CMD_WD_TIME, timeout * 10); if (ret < 0) return ret; wdt->timeout = timeout; return 0; } static int menf21bmc_wdt_ping(struct watchdog_device *wdt) { struct menf21bmc_wdt *drv_data = watchdog_get_drvdata(wdt); return i2c_smbus_write_byte(drv_data->i2c_client, BMC_CMD_WD_TRIG); } static const struct watchdog_info menf21bmc_wdt_info = { .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, .identity = DEVNAME, }; static const struct watchdog_ops menf21bmc_wdt_ops = { .owner = THIS_MODULE, .start = menf21bmc_wdt_start, .stop = menf21bmc_wdt_stop, .ping = menf21bmc_wdt_ping, .set_timeout = menf21bmc_wdt_settimeout, }; static int menf21bmc_wdt_probe(struct platform_device *pdev) { int ret, bmc_timeout; struct menf21bmc_wdt *drv_data; struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent); drv_data = devm_kzalloc(&pdev->dev, sizeof(struct menf21bmc_wdt), GFP_KERNEL); if (!drv_data) return -ENOMEM; drv_data->wdt.ops = &menf21bmc_wdt_ops; drv_data->wdt.info = &menf21bmc_wdt_info; drv_data->wdt.min_timeout = BMC_WD_TIMEOUT_MIN; drv_data->wdt.max_timeout = BMC_WD_TIMEOUT_MAX; drv_data->wdt.parent = &pdev->dev; drv_data->i2c_client = i2c_client; /* * Get the current wdt timeout value from the BMC because * the BMC will save the value set before if the system restarts. */ bmc_timeout = i2c_smbus_read_word_data(drv_data->i2c_client, BMC_CMD_WD_TIME); if (bmc_timeout < 0) { dev_err(&pdev->dev, "failed to get current WDT timeout\n"); return bmc_timeout; } watchdog_init_timeout(&drv_data->wdt, bmc_timeout / 10, &pdev->dev); watchdog_set_nowayout(&drv_data->wdt, nowayout); watchdog_set_drvdata(&drv_data->wdt, drv_data); platform_set_drvdata(pdev, drv_data); ret = menf21bmc_wdt_set_bootstatus(drv_data); if (ret < 0) { dev_err(&pdev->dev, "failed to set Watchdog bootstatus\n"); return ret; } ret = watchdog_register_device(&drv_data->wdt); if (ret) { dev_err(&pdev->dev, "failed to register Watchdog device\n"); return ret; } dev_info(&pdev->dev, "MEN 14F021P00 BMC Watchdog device enabled\n"); return 0; } static int menf21bmc_wdt_remove(struct platform_device *pdev) { struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev); dev_warn(&pdev->dev, "Unregister MEN 14F021P00 BMC Watchdog device, board may reset\n"); watchdog_unregister_device(&drv_data->wdt); return 0; } static void menf21bmc_wdt_shutdown(struct platform_device *pdev) { struct menf21bmc_wdt *drv_data = platform_get_drvdata(pdev); i2c_smbus_write_word_data(drv_data->i2c_client, BMC_CMD_WD_OFF, BMC_WD_OFF_VAL); } static struct platform_driver menf21bmc_wdt = { .driver = { .name = DEVNAME, }, .probe = menf21bmc_wdt_probe, .remove = menf21bmc_wdt_remove, .shutdown = menf21bmc_wdt_shutdown, }; module_platform_driver(menf21bmc_wdt); MODULE_DESCRIPTION("MEN 14F021P00 BMC Watchdog driver"); MODULE_AUTHOR("Andreas Werner "); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:menf21bmc_wdt"); /i2c/other?id=e6e7b48b295afa5a5ab440de0a94d9ad8b3ce2d0'>e6e7b48b295afa5a5ab440de0a94d9ad8b3ce2d0 (diff)
drm/atomic: Fix double free in drm_atomic_state_default_clear
drm_atomic_helper_page_flip and drm_atomic_ioctl set their own events in crtc_state->event. But when it's set the event is freed in 2 places. Solve this by only freeing the event in the atomic ioctl when it allocated its own event. This has been broken twice. The first time when the code was introduced, but only in the corner case when an event is allocated, but more crtc's were included by atomic check and then failing. This can mostly happen when you do an atomic modeset in i915 and the display clock is changed, which forces all crtc's to be included to the state. This has been broken worse by adding in-fences support, which caused the double free to be done unconditionally. [IGT] kms_rotation_crc: starting subtest primary-rotation-180 ============================================================================= BUG kmalloc-128 (Tainted: G U ): Object already free ----------------------------------------------------------------------------- Disabling lock debugging due to kernel taint INFO: Allocated in drm_atomic_helper_setup_commit+0x285/0x2f0 [drm_kms_helper] age=0 cpu=3 pid=1529 ___slab_alloc+0x308/0x3b0 __slab_alloc+0xd/0x20 kmem_cache_alloc_trace+0x92/0x1c0 drm_atomic_helper_setup_commit+0x285/0x2f0 [drm_kms_helper] intel_atomic_commit+0x35/0x4f0 [i915] drm_atomic_commit+0x46/0x50 [drm] drm_mode_atomic_ioctl+0x7d4/0xab0 [drm] drm_ioctl+0x2b3/0x490 [drm] do_vfs_ioctl+0x69c/0x700 SyS_ioctl+0x4e/0x80 entry_SYSCALL_64_fastpath+0x13/0x94 INFO: Freed in drm_event_cancel_free+0xa3/0xb0 [drm] age=0 cpu=3 pid=1529 __slab_free+0x48/0x2e0 kfree+0x159/0x1a0 drm_event_cancel_free+0xa3/0xb0 [drm] drm_mode_atomic_ioctl+0x86d/0xab0 [drm] drm_ioctl+0x2b3/0x490 [drm] do_vfs_ioctl+0x69c/0x700 SyS_ioctl+0x4e/0x80 entry_SYSCALL_64_fastpath+0x13/0x94 INFO: Slab 0xffffde1f0997b080 objects=17 used=2 fp=0xffff92fb65ec2578 flags=0x200000000008101 INFO: Object 0xffff92fb65ec2578 @offset=1400 fp=0xffff92fb65ec2ae8 Redzone ffff92fb65ec2570: bb bb bb bb bb bb bb bb ........ Object ffff92fb65ec2578: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec2588: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec2598: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25a8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25b8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25c8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25d8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25e8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk. Redzone ffff92fb65ec25f8: bb bb bb bb bb bb bb bb ........ Padding ffff92fb65ec2738: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ CPU: 3 PID: 180 Comm: kworker/3:2 Tainted: G BU 4.10.0-rc6-patser+ #5039 Hardware name: /NUC5PPYB, BIOS PYBSWCEL.86A.0031.2015.0601.1712 06/01/2015 Workqueue: events intel_atomic_helper_free_state [i915] Call Trace: dump_stack+0x4d/0x6d print_trailer+0x20c/0x220 free_debug_processing+0x1c6/0x330 ? drm_atomic_state_default_clear+0xf7/0x1c0 [drm] __slab_free+0x48/0x2e0 ? drm_atomic_state_default_clear+0xf7/0x1c0 [drm] kfree+0x159/0x1a0 drm_atomic_state_default_clear+0xf7/0x1c0 [drm] ? drm_atomic_state_clear+0x30/0x30 [drm] intel_atomic_state_clear+0xd/0x20 [i915] drm_atomic_state_clear+0x1a/0x30 [drm] __drm_atomic_state_free+0x13/0x60 [drm] intel_atomic_helper_free_state+0x5d/0x70 [i915] process_one_work+0x260/0x4a0 worker_thread+0x2d1/0x4f0 kthread+0x127/0x130 ? process_one_work+0x4a0/0x4a0 ? kthread_stop+0x120/0x120 ret_from_fork+0x29/0x40 FIX kmalloc-128: Object at 0xffff92fb65ec2578 not freed Fixes: 3b24f7d67581 ("drm/atomic: Add struct drm_crtc_commit to track async updates") Fixes: 9626014258a5 ("drm/fence: add in-fences support") Cc: <stable@vger.kernel.org> # v4.8+ Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/1485854725-27640-1-git-send-email-maarten.lankhorst@linux.intel.com
Diffstat (limited to 'sound/i2c/other')