chip->dev = parent;
chip->npwm = npwm;
+ chip->uses_pwmchip_alloc = true;
pwmchip_set_drvdata(chip, pwmchip_priv(chip));
if (!chip || !pwmchip_parent(chip) || !chip->ops || !chip->npwm)
return -EINVAL;
+ /*
+ * a struct pwm_chip must be allocated using (devm_)pwmchip_alloc,
+ * otherwise the embedded struct device might disappear too early
+ * resulting in memory corruption.
+ * Catch drivers that were not converted appropriately.
+ */
+ if (!chip->uses_pwmchip_alloc)
+ return -EINVAL;
+
if (!pwm_ops_check(chip))
return -EINVAL;
* @npwm: number of PWMs controlled by this chip
* @of_xlate: request a PWM device given a device tree PWM specifier
* @atomic: can the driver's ->apply() be called in atomic context
+ * @uses_pwmchip_alloc: signals if pwmchip_allow was used to allocate this chip
* @driver_data: Private pointer for driver specific info
* @pwms: array of PWM devices allocated by the framework
*/
bool atomic;
/* only used internally by the PWM framework */
+ bool uses_pwmchip_alloc;
void *driver_data;
struct pwm_device *pwms;
};