if (!state)
return NULL;
+ state->num_connector = ACCESS_ONCE(dev->mode_config.num_connector);
+
state->crtcs = kcalloc(dev->mode_config.num_crtc,
sizeof(*state->crtcs), GFP_KERNEL);
if (!state->crtcs)
sizeof(*state->plane_states), GFP_KERNEL);
if (!state->plane_states)
goto fail;
- state->connectors = kcalloc(dev->mode_config.num_connector,
+ state->connectors = kcalloc(state->num_connector,
sizeof(*state->connectors),
GFP_KERNEL);
if (!state->connectors)
goto fail;
- state->connector_states = kcalloc(dev->mode_config.num_connector,
+ state->connector_states = kcalloc(state->num_connector,
sizeof(*state->connector_states),
GFP_KERNEL);
if (!state->connector_states)
DRM_DEBUG_KMS("Clearing atomic state %p\n", state);
- for (i = 0; i < config->num_connector; i++) {
+ for (i = 0; i < state->num_connector; i++) {
struct drm_connector *connector = state->connectors[i];
if (!connector)
index = drm_connector_index(connector);
+ /*
+ * Construction of atomic state updates can race with a connector
+ * hot-add which might overflow. In this case flip the table and just
+ * restart the entire ioctl - no one is fast enough to livelock a cpu
+ * with physical hotplug events anyway.
+ *
+ * Note that we only grab the indexes once we have the right lock to
+ * prevent hotplug/unplugging of connectors. So removal is no problem,
+ * at most the array is a bit too large.
+ */
+ if (index >= state->num_connector) {
+ DRM_DEBUG_KMS("Hot-added connector would overflow state array, restarting\n");
+ return -EAGAIN;
+ }
+
if (state->connector_states[index])
return state->connector_states[index];
drm_atomic_connectors_for_crtc(struct drm_atomic_state *state,
struct drm_crtc *crtc)
{
- int nconnectors = state->dev->mode_config.num_connector;
int i, num_connected_connectors = 0;
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < state->num_connector; i++) {
struct drm_connector_state *conn_state;
conn_state = state->connector_states[i];
mode_fixup(struct drm_atomic_state *state)
{
int ncrtcs = state->dev->mode_config.num_crtc;
- int nconnectors = state->dev->mode_config.num_connector;
struct drm_crtc_state *crtc_state;
struct drm_connector_state *conn_state;
int i;
drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode);
}
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < state->num_connector; i++) {
struct drm_encoder_helper_funcs *funcs;
struct drm_encoder *encoder;
struct drm_atomic_state *state)
{
int ncrtcs = dev->mode_config.num_crtc;
- int nconnectors = dev->mode_config.num_connector;
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
int i, ret;
}
}
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < state->num_connector; i++) {
/*
* This only sets crtc->mode_changed for routing changes,
* drivers must set crtc->mode_changed themselves when connector
disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
{
int ncrtcs = old_state->dev->mode_config.num_crtc;
- int nconnectors = old_state->dev->mode_config.num_connector;
int i;
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < old_state->num_connector; i++) {
struct drm_connector_state *old_conn_state;
struct drm_connector *connector;
struct drm_encoder_helper_funcs *funcs;
static void
set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state)
{
- int nconnectors = dev->mode_config.num_connector;
int ncrtcs = old_state->dev->mode_config.num_crtc;
int i;
/* clear out existing links */
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < old_state->num_connector; i++) {
struct drm_connector *connector;
connector = old_state->connectors[i];
}
/* set new links */
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < old_state->num_connector; i++) {
struct drm_connector *connector;
connector = old_state->connectors[i];
crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
{
int ncrtcs = old_state->dev->mode_config.num_crtc;
- int nconnectors = old_state->dev->mode_config.num_connector;
int i;
for (i = 0; i < ncrtcs; i++) {
funcs->mode_set_nofb(crtc);
}
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < old_state->num_connector; i++) {
struct drm_connector *connector;
struct drm_crtc_state *new_crtc_state;
struct drm_encoder_helper_funcs *funcs;
struct drm_atomic_state *old_state)
{
int ncrtcs = old_state->dev->mode_config.num_crtc;
- int nconnectors = old_state->dev->mode_config.num_connector;
int i;
for (i = 0; i < ncrtcs; i++) {
funcs->commit(crtc);
}
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < old_state->num_connector; i++) {
struct drm_connector *connector;
struct drm_encoder_helper_funcs *funcs;
struct drm_encoder *encoder;
{
struct drm_device *dev = set->crtc->dev;
struct drm_connector_state *conn_state;
- int nconnectors = state->dev->mode_config.num_connector;
int ncrtcs = state->dev->mode_config.num_crtc;
int ret, i, j;
}
/* Then recompute connector->crtc links and crtc enabling state. */
- for (i = 0; i < nconnectors; i++) {
+ for (i = 0; i < state->num_connector; i++) {
struct drm_connector *connector;
connector = state->connectors[i];