Skip to content

Commit 08d9bc9

Browse files
Ander Conselvan de Oliveirajnikula
authored andcommitted
drm/i915: Allocate connector state together with the connectors
Connector states were being allocated in intel_setup_outputs() in loop over all connectors. That meant hot-added connectors would have a NULL state. Since the change to use a struct drm_atomic_state for the legacy modeset, connector states are necessary for the i915 driver to function properly, so that would lead to oopses. Broken by commit 944b0c7 Author: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com> Date: Fri Mar 20 16:18:07 2015 +0200 drm/i915: Copy the staged connector config to the legacy atomic state v2: Fix test for intel_connector_init() success in lvds and sdvo (PRTS) Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com> Reported-and-tested-by: Nicolas Kalkhof <nkalkhof@web.de> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
1 parent af8fcb9 commit 08d9bc9

12 files changed

Lines changed: 64 additions & 46 deletions

File tree

‎drivers/gpu/drm/i915/intel_crt.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ void intel_crt_init(struct drm_device *dev)
851851
if (!crt)
852852
return;
853853

854-
intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
854+
intel_connector = intel_connector_alloc();
855855
if (!intel_connector) {
856856
kfree(crt);
857857
return;

‎drivers/gpu/drm/i915/intel_ddi.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
22002200
struct intel_connector *connector;
22012201
enum port port = intel_dig_port->port;
22022202

2203-
connector = kzalloc(sizeof(*connector), GFP_KERNEL);
2203+
connector = intel_connector_alloc();
22042204
if (!connector)
22052205
return NULL;
22062206

@@ -2219,7 +2219,7 @@ intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
22192219
struct intel_connector *connector;
22202220
enum port port = intel_dig_port->port;
22212221

2222-
connector = kzalloc(sizeof(*connector), GFP_KERNEL);
2222+
connector = intel_connector_alloc();
22232223
if (!connector)
22242224
return NULL;
22252225

‎drivers/gpu/drm/i915/intel_display.c‎

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5636,6 +5636,34 @@ static void intel_connector_check_state(struct intel_connector *connector)
56365636
}
56375637
}
56385638

5639+
int intel_connector_init(struct intel_connector *connector)
5640+
{
5641+
struct drm_connector_state *connector_state;
5642+
5643+
connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL);
5644+
if (!connector_state)
5645+
return -ENOMEM;
5646+
5647+
connector->base.state = connector_state;
5648+
return 0;
5649+
}
5650+
5651+
struct intel_connector *intel_connector_alloc(void)
5652+
{
5653+
struct intel_connector *connector;
5654+
5655+
connector = kzalloc(sizeof *connector, GFP_KERNEL);
5656+
if (!connector)
5657+
return NULL;
5658+
5659+
if (intel_connector_init(connector) < 0) {
5660+
kfree(connector);
5661+
return NULL;
5662+
}
5663+
5664+
return connector;
5665+
}
5666+
56395667
/* Even simpler default implementation, if there's really no special case to
56405668
* consider. */
56415669
void intel_connector_dpms(struct drm_connector *connector, int mode)
@@ -13003,7 +13031,6 @@ static void intel_setup_outputs(struct drm_device *dev)
1300313031
{
1300413032
struct drm_i915_private *dev_priv = dev->dev_private;
1300513033
struct intel_encoder *encoder;
13006-
struct drm_connector *connector;
1300713034
bool dpd_is_edp = false;
1300813035

1300913036
intel_lvds_init(dev);
@@ -13139,39 +13166,6 @@ static void intel_setup_outputs(struct drm_device *dev)
1313913166
if (SUPPORTS_TV(dev))
1314013167
intel_tv_init(dev);
1314113168

13142-
/*
13143-
* FIXME: We don't have full atomic support yet, but we want to be
13144-
* able to enable/test plane updates via the atomic interface in the
13145-
* meantime. However as soon as we flip DRIVER_ATOMIC on, the DRM core
13146-
* will take some atomic codepaths to lookup properties during
13147-
* drmModeGetConnector() that unconditionally dereference
13148-
* connector->state.
13149-
*
13150-
* We create a dummy connector state here for each connector to ensure
13151-
* the DRM core doesn't try to dereference a NULL connector->state.
13152-
* The actual connector properties will never be updated or contain
13153-
* useful information, but since we're doing this specifically for
13154-
* testing/debug of the plane operations (and only when a specific
13155-
* kernel module option is given), that shouldn't really matter.
13156-
*
13157-
* We are also relying on these states to convert the legacy mode set
13158-
* to use a drm_atomic_state struct. The states are kept consistent
13159-
* with actual state, so that it is safe to rely on that instead of
13160-
* the staged config.
13161-
*
13162-
* Once atomic support for crtc's + connectors lands, this loop should
13163-
* be removed since we'll be setting up real connector state, which
13164-
* will contain Intel-specific properties.
13165-
*/
13166-
list_for_each_entry(connector,
13167-
&dev->mode_config.connector_list,
13168-
head) {
13169-
if (!WARN_ON(connector->state)) {
13170-
connector->state = kzalloc(sizeof(*connector->state),
13171-
GFP_KERNEL);
13172-
}
13173-
}
13174-
1317513169
intel_psr_init(dev);
1317613170

1317713171
for_each_intel_encoder(dev, encoder) {

‎drivers/gpu/drm/i915/intel_dp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5590,7 +5590,7 @@ intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
55905590
if (!intel_dig_port)
55915591
return;
55925592

5593-
intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
5593+
intel_connector = intel_connector_alloc();
55945594
if (!intel_connector) {
55955595
kfree(intel_dig_port);
55965596
return;

‎drivers/gpu/drm/i915/intel_dp_mst.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topolo
415415
struct drm_connector *connector;
416416
int i;
417417

418-
intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
418+
intel_connector = intel_connector_alloc();
419419
if (!intel_connector)
420420
return NULL;
421421

‎drivers/gpu/drm/i915/intel_drv.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,8 @@ void intel_crtc_restore_mode(struct drm_crtc *crtc);
930930
void intel_crtc_control(struct drm_crtc *crtc, bool enable);
931931
void intel_crtc_update_dpms(struct drm_crtc *crtc);
932932
void intel_encoder_destroy(struct drm_encoder *encoder);
933+
int intel_connector_init(struct intel_connector *);
934+
struct intel_connector *intel_connector_alloc(void);
933935
void intel_connector_dpms(struct drm_connector *, int mode);
934936
bool intel_connector_get_hw_state(struct intel_connector *connector);
935937
void intel_modeset_check_state(struct drm_device *dev);

‎drivers/gpu/drm/i915/intel_dsi.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ void intel_dsi_init(struct drm_device *dev)
10071007
if (!intel_dsi)
10081008
return;
10091009

1010-
intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
1010+
intel_connector = intel_connector_alloc();
10111011
if (!intel_connector) {
10121012
kfree(intel_dsi);
10131013
return;

‎drivers/gpu/drm/i915/intel_dvo.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void intel_dvo_init(struct drm_device *dev)
469469
if (!intel_dvo)
470470
return;
471471

472-
intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
472+
intel_connector = intel_connector_alloc();
473473
if (!intel_connector) {
474474
kfree(intel_dvo);
475475
return;

‎drivers/gpu/drm/i915/intel_hdmi.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
17501750
if (!intel_dig_port)
17511751
return;
17521752

1753-
intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
1753+
intel_connector = intel_connector_alloc();
17541754
if (!intel_connector) {
17551755
kfree(intel_dig_port);
17561756
return;

‎drivers/gpu/drm/i915/intel_lvds.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,12 @@ void intel_lvds_init(struct drm_device *dev)
946946
return;
947947
}
948948

949+
if (intel_connector_init(&lvds_connector->base) < 0) {
950+
kfree(lvds_connector);
951+
kfree(lvds_encoder);
952+
return;
953+
}
954+
949955
lvds_encoder->attached_connector = lvds_connector;
950956

951957
intel_encoder = &lvds_encoder->base;

0 commit comments

Comments
 (0)