Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/radeon: convert bios_hardcoded_edid to drm_edid

Instead of manually passing around 'struct edid *' and its size,
use 'struct drm_edid', which encapsulates a validated combination of
both.

As the drm_edid_ can handle NULL gracefully, the explicit checks can be
dropped.

Also save a few characters by transforming '&array[0]' to the equivalent
'array' and using 'max_t(int, ...)' instead of manual casts.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Thomas Weißschuh and committed by
Alex Deucher
c6bb3acf aeb81b62

+16 -37
+6 -11
drivers/gpu/drm/radeon/radeon_atombios.c
··· 1716 1716 case LCD_FAKE_EDID_PATCH_RECORD_TYPE: 1717 1717 fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record; 1718 1718 if (fake_edid_record->ucFakeEDIDLength) { 1719 - struct edid *edid; 1719 + const struct drm_edid *edid; 1720 1720 int edid_size; 1721 1721 1722 1722 if (fake_edid_record->ucFakeEDIDLength == 128) 1723 1723 edid_size = fake_edid_record->ucFakeEDIDLength; 1724 1724 else 1725 1725 edid_size = fake_edid_record->ucFakeEDIDLength * 128; 1726 - edid = kmemdup(&fake_edid_record->ucFakeEDIDString[0], 1727 - edid_size, GFP_KERNEL); 1728 - if (edid) { 1729 - if (drm_edid_is_valid(edid)) { 1730 - rdev->mode_info.bios_hardcoded_edid = edid; 1731 - rdev->mode_info.bios_hardcoded_edid_size = edid_size; 1732 - } else { 1733 - kfree(edid); 1734 - } 1735 - } 1726 + edid = drm_edid_alloc(fake_edid_record->ucFakeEDIDString, edid_size); 1727 + if (drm_edid_valid(edid)) 1728 + rdev->mode_info.bios_hardcoded_edid = edid; 1729 + else 1730 + drm_edid_free(edid); 1736 1731 record += struct_size(fake_edid_record, 1737 1732 ucFakeEDIDString, 1738 1733 edid_size);
+5 -21
drivers/gpu/drm/radeon/radeon_combios.c
··· 370 370 bool radeon_combios_check_hardcoded_edid(struct radeon_device *rdev) 371 371 { 372 372 int edid_info, size; 373 - struct edid *edid; 373 + const struct drm_edid *edid; 374 374 unsigned char *raw; 375 375 edid_info = combios_get_table_offset(rdev_to_drm(rdev), COMBIOS_HARDCODED_EDID_TABLE); 376 376 if (!edid_info) ··· 378 378 379 379 raw = rdev->bios + edid_info; 380 380 size = EDID_LENGTH * (raw[0x7e] + 1); 381 - edid = kmalloc(size, GFP_KERNEL); 382 - if (edid == NULL) 383 - return false; 381 + edid = drm_edid_alloc(raw, size); 384 382 385 - memcpy((unsigned char *)edid, raw, size); 386 - 387 - if (!drm_edid_is_valid(edid)) { 388 - kfree(edid); 383 + if (!drm_edid_valid(edid)) { 384 + drm_edid_free(edid); 389 385 return false; 390 386 } 391 387 392 388 rdev->mode_info.bios_hardcoded_edid = edid; 393 - rdev->mode_info.bios_hardcoded_edid_size = size; 394 389 return true; 395 390 } 396 391 ··· 393 398 struct edid * 394 399 radeon_bios_get_hardcoded_edid(struct radeon_device *rdev) 395 400 { 396 - struct edid *edid; 397 - 398 - if (rdev->mode_info.bios_hardcoded_edid) { 399 - edid = kmalloc(rdev->mode_info.bios_hardcoded_edid_size, GFP_KERNEL); 400 - if (edid) { 401 - memcpy((unsigned char *)edid, 402 - (unsigned char *)rdev->mode_info.bios_hardcoded_edid, 403 - rdev->mode_info.bios_hardcoded_edid_size); 404 - return edid; 405 - } 406 - } 407 - return NULL; 401 + return drm_edid_duplicate(drm_edid_raw(rdev->mode_info.bios_hardcoded_edid)); 408 402 } 409 403 410 404 static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rdev,
+2 -2
drivers/gpu/drm/radeon/radeon_connectors.c
··· 1059 1059 */ 1060 1060 if ((!rdev->is_atom_bios) && 1061 1061 (ret == connector_status_disconnected) && 1062 - rdev->mode_info.bios_hardcoded_edid_size) { 1062 + rdev->mode_info.bios_hardcoded_edid) { 1063 1063 ret = connector_status_connected; 1064 1064 } 1065 1065 ··· 1392 1392 out: 1393 1393 if ((!rdev->is_atom_bios) && 1394 1394 (ret == connector_status_disconnected) && 1395 - rdev->mode_info.bios_hardcoded_edid_size) { 1395 + rdev->mode_info.bios_hardcoded_edid) { 1396 1396 radeon_connector->use_digital = true; 1397 1397 ret = connector_status_connected; 1398 1398 }
+1 -1
drivers/gpu/drm/radeon/radeon_display.c
··· 1658 1658 rdev->mode_info.mode_config_initialized = false; 1659 1659 } 1660 1660 1661 - kfree(rdev->mode_info.bios_hardcoded_edid); 1661 + drm_edid_free(rdev->mode_info.bios_hardcoded_edid); 1662 1662 1663 1663 /* free i2c buses */ 1664 1664 radeon_i2c_fini(rdev);
+2 -2
drivers/gpu/drm/radeon/radeon_mode.h
··· 39 39 #include <linux/i2c-algo-bit.h> 40 40 41 41 struct edid; 42 + struct drm_edid; 42 43 struct radeon_bo; 43 44 struct radeon_device; 44 45 ··· 263 262 /* Output CSC */ 264 263 struct drm_property *output_csc_property; 265 264 /* hardcoded DFP edid from BIOS */ 266 - struct edid *bios_hardcoded_edid; 267 - int bios_hardcoded_edid_size; 265 + const struct drm_edid *bios_hardcoded_edid; 268 266 269 267 /* firmware flags */ 270 268 u16 firmware_flags;