Skip to contentSkip to conversation

drm: Use new mode_valid() helpers in connector probe helper

bug report Dan Carpenter 1 participant 1 message Dec 8, 2025

lore
Share & tools
lore
#0 lore raw

Hello Jose Abreu,

Commit 97f973d65260 ("drm: Use new mode_valid() helpers in connector probe helper") from May 25, 2017 (linux-next), leads to the following Smatch static checker warning:

	drivers/gpu/drm/drm_probe_helper.c:102 drm_mode_validate_pipeline()
	warn: set error code if '*status != 0'

drivers/gpu/drm/drm_probe_helper.c

    89 static int
    90 drm_mode_validate_pipeline(struct drm_display_mode *mode,
    91                            struct drm_connector *connector,
    92                            struct drm_modeset_acquire_ctx *ctx,
    93                            enum drm_mode_status *status)
    94 {
    95         struct drm_device *dev = connector->dev;
    96         struct drm_encoder *encoder;
    97         int ret;
    98 
    99         /* Step 1: Validate against connector */
    100         ret = drm_connector_mode_valid(connector, mode, ctx, status);
    101         if (ret || *status != MODE_OK)

--> 102 return ret;

The caller expects ret to be set on error, so if only *status is set to an error this will do something bad.

    103 
    104         /* Step 2: Validate against encoders and crtcs */
    105         drm_connector_for_each_possible_encoder(connector, encoder) {
    106                 struct drm_bridge *bridge;
    107                 struct drm_crtc *crtc;
    108 
    109                 *status = drm_encoder_mode_valid(encoder, mode);
    110                 if (*status != MODE_OK) {
    111                         /* No point in continuing for crtc check as this encoder
    112                          * will not accept the mode anyway. If all encoders
    113                          * reject the mode then, at exit, ret will not be
    114                          * MODE_OK. */
    115                         continue;
    116                 }
    117 
    118                 bridge = drm_bridge_chain_get_first_bridge(encoder);
    119                 *status = drm_bridge_chain_mode_valid(bridge,
    120                                                       &connector->display_info,
    121                                                       mode);
    122                 drm_bridge_put(bridge);
    123                 if (*status != MODE_OK) {
    124                         /* There is also no point in continuing for crtc check
    125                          * here. */
    126                         continue;
    127                 }
    128 
    129                 drm_for_each_crtc(crtc, dev) {
    130                         if (!drm_encoder_crtc_ok(encoder, crtc))
    131                                 continue;
    132 
    133                         *status = drm_crtc_mode_valid(crtc, mode);
    134                         if (*status == MODE_OK) {
    135                                 /* If we get to this point there is at least
    136                                  * one combination of encoder+crtc that works
    137                                  * for this mode. Lets return now. */
    138                                 return 0;
    139                         }
    140                 }
    141         }
    142 
    143         return 0;
    144 }

regards,
dan carpenter